c++ - QString, Parse and replace some specific sections -
suppose have string this:
qstring str = "23+34-343+$t$-3+$opc$";
i want replace every sections enclosed 2 $ replaced %0, %1 , on. above example : "23+34-343+%0-3+%1"
i can detect sections using qregularexpression , pattern: "\$.+?\$"
what best , optimized way (not use loops , indices) replace sections %0, %1, %2 , on.
how this:
qstring str = "23+34-343+$t$-3+$opc$"; qregexp rx; rx.setminimal(true); rx.setpattern("\\$.+\\$"); str.replace(rx, "x"); //first replace every pattern 'x' for(int i=0 ;str.indexof("x")!=-1; i++) str.replace(str.indexof("x"), 1,"%"+qstring::number(i));
Comments
Post a Comment