PDA

View Full Version : getting the substring with delimiter



meena
6th July 2010, 11:42
Hi
Any way to get the substring with delimiter. like if string is 992.968.3.22, then getting 4 substrings 992, 968, 3 & 22.(here delimiter is ".")

Zlatomir
6th July 2010, 11:46
Yes that is possible, you can use QStringList to hold the list of strings (sub-strings):


QStringList list;
list << str.split(".");

borisbn
6th July 2010, 13:02
or you can use QString::section


QString s0 = ipString.section( ".", 0, 0 );
QString s1 = ipString.section( ".", 1, 1 );
and so on


p.s. split returns QStringList, that's why you can assign it right to stringlist, without operator <<


QStringList list = ipString.split( "." );

Zlatomir
6th July 2010, 13:38
@borisbn Good point with the split return type, thanks