c++ - Using QRegExp replace words that are in a QString -


i have qstring contains list of reserved words. need parse string, seaching words contained in first 1 , prepended '\' , modify these ocorrences.

example:

qstring reserved = "command1,command2,command3"  qstring = "\command1 \command2command1 \command3 command2 sometext"  parsestring(a, reserved) = "<input com="command1"></input> \command2command1 <input com="command3"></input> command2 sometext" 

i know have use qregexp, didn't find how use qregexp check if word in list declared. can guys me out?

thanks in advance

i split reservedwords list qstringlist iterate on each reserved word. prepend \ character (it needs escaped in qstring), , use indexof() function see if reserved word exists in input string.

void parsestring(qstring input, qstring reservedwords) {     qstringlist reservedwordslist = reserved.split(',');     foreach(qstring reservedword, reservedwordslist)     {         reservedword = "\\" + reservedword;         int indexofreservedword = input.indexof(reservedword);         if(indexofreservedword >= 0)         {             // found match, processing here         }     } } 

Comments