Qt-interest Archive, May 2008
Split QString into left/right substrings ?
Message 1 in thread
Given, say, a QString containing:
"one, two, three, four, five"
can someone suggest a straightforward method to split this
into "one" and " two, three, four, five" i.e. at the first
occurrence of the "," separator - I can't see any obvious
QString method that does this trivially.
--
[ signature omitted ]
Message 2 in thread
På Lørdag 03 mai 2008 , 13:07:00 skrev Stephen Collyer:
> Given, say, a QString containing:
>
> "one, two, three, four, five"
>
> can someone suggest a straightforward method to split this
> into "one" and " two, three, four, five" i.e. at the first
> occurrence of the "," separator - I can't see any obvious
> QString method that does this trivially.
Look into combining QString::chop() and QString::right().
--
[ signature omitted ]
Message 3 in thread
Personally, I would use QtString::split and QtString::join for this.
Gives you a lot more parsing options for the particles.
Christopher Rasch-Olsen Raa wrote:
> På Lørdag 03 mai 2008 , 13:07:00 skrev Stephen Collyer:
>
>> Given, say, a QString containing:
>>
>> "one, two, three, four, five"
>>
>> can someone suggest a straightforward method to split this
>> into "one" and " two, three, four, five" i.e. at the first
>> occurrence of the "," separator - I can't see any obvious
>> QString method that does this trivially.
>>
>
> Look into combining QString::chop() and QString::right().
>
> --
> Christopher
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>
>
--
[ signature omitted ]
Message 4 in thread
Personally, I would use QtString::split and QtString::join for this.
Gives you a lot more parsing options for the particles.
Christopher Rasch-Olsen Raa wrote:
> På Lørdag 03 mai 2008 , 13:07:00 skrev Stephen Collyer:
>
>> Given, say, a QString containing:
>>
>> "one, two, three, four, five"
>>
>> can someone suggest a straightforward method to split this
>> into "one" and " two, three, four, five" i.e. at the first
>> occurrence of the "," separator - I can't see any obvious
>> QString method that does this trivially.
>>
>
> Look into combining QString::chop() and QString::right().
>
> --
> Christopher
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>
>
--
[ signature omitted ]
Message 5 in thread
On Saturday 03 May 2008 14:46:32 David Fuess wrote:
> Personally, I would use QtString::split and QtString::join for this.
> Gives you a lot more parsing options for the particles.
Another alternative is QString::indexOf(), QString::left() and
QString::right().
HTH,
Sean
--
[ signature omitted ]
Message 6 in thread
Try this code:
QString str = "one, two, three, four, five";
QRegExp sep("^*,");
qDebug() << str.section(sep, 0, 0);
qDebug() << str.section(sep, 1);
--
[ signature omitted ]