开发者

QString find method in Qt?

Is there any Find method in Qstring in Qt like CString find method ? My Requirement is i have one Qstring

QString strdata = "Sunday,01:30 - 17:30";

I want to split them. Now i want s1 = Sunday s2 = 01:30 s开发者_运维技巧3 = 17:30

Where s1,s2,s3 are QString

Thanks.


QString strdata = "Sunday,01:30 - 17:30";

QStringList stringlist_0;
QStringList stringlist_1;

stringlist_0 = strdata.split( "," );
stringlist_1 = stringlist_0[1].split( " - " );

QString day = stringlist_0[0];
QString begin_time = stringlist_1[0];
QString end_time = stringlist_1[1];


You can also use regular expression to split a string:

QStringList list = strdata.split(QRegExp("\\s|-|,"), QString::SkipEmptyParts);


First split it by ',' then split the tail by '-'.

Use split: http://doc.qt.io/qt-5/qstring.html#split-3

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜