PDA

View Full Version : how to get the string out by multi separator?



SamT
17th April 2010, 18:45
Hi,

if there is a QSting str1 = 1111, aabbcc,"3,231,301", 33, "43,103,359", 32.335

I know I can use str1.section(',' 0,0) to get the substring 1111 from str1. How can I get the substring "3,231,301" by QString section function? I think I should use QRegExp but don't know how to implement.


Can somebody help? Thanks!

Nik8768
17th April 2010, 19:08
QString str = "1111, aabbcc,\"3,231,301\", 33, \"43,103,359\", 32.335";
QRegExp rx("(,\"(\\d|,)*\",)");
rx.indexIn(str);
QStringList list = rx.capturedTexts();
QString finalStr = list.at(0);

"finalStr" is what you wanted..