Parsing string
Unsolved
Qt 6
-
@fari35 said in Parsing string:
How can I do that in Qt?
-
Already answered on so: 'Use a combination of std::string::find and std::string::substr, or their QString equivalents QString::indexOf and QString::mid.'
-
Here I have Developed logic for you..
you can try it.QString Check = "<abc>0200</abc><xyz>10101</xyz>"; /// YOUR STRING QVector<QRegExp> rx; rx.push_back(QRegExp("<abc>([a-zA-Z0-9 ]+)</abc>")); rx.push_back(QRegExp("<xyz>([a-zA-Z0-9 ]+)</xyz>")); QStringList list; for(int i = 0 ; i < rx.size() ; i++) { int pos = 0; while ((pos = rx.at(i).indexIn(Check, pos)) != -1) { list << rx.at(i).cap(1); pos += rx.at(i).matchedLength(); } }
Here i have used
QRegExp
Class.
i have add tag names in Expression And extract the data between from it and store the all data in QStringListYou just have to make Expression and add in
QVector<QRegex>
as i used. -
@Ketan__Patel__0011 please do not use QRegExp, it was deprecated in Qt 5 and removed in Qt 6. Use QRegularExpression.