Bokambo
Bokambo

Reputation: 4480

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 s3 = 17:30

Where s1,s2,s3 are QString

Thanks.

Upvotes: 2

Views: 4051

Answers (3)

Wojtek Turowicz
Wojtek Turowicz

Reputation: 4131

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

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

Upvotes: 2

Stephen Chu
Stephen Chu

Reputation: 12832

You can also use regular expression to split a string:

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

Upvotes: 2

Exa
Exa

Reputation: 4110

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];

Upvotes: 3

Related Questions