Results 1 to 4 of 4

Thread: getting the substring with delimiter

  1. #1
    Join Date
    May 2010
    Location
    Bangalore, India.
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default getting the substring with delimiter

    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 ".")

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: getting the substring with delimiter

    Yes that is possible, you can use QStringList to hold the list of strings (sub-strings):
    Qt Code:
    1. list << str.split(".");
    To copy to clipboard, switch view to plain text mode 

  3. The following 2 users say thank you to Zlatomir for this useful post:

    meena (6th July 2010), Septi (6th July 2010)

  4. #3
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: getting the substring with delimiter

    or you can use QString::section
    Qt Code:
    1. QString s0 = ipString.section( ".", 0, 0 );
    2. QString s1 = ipString.section( ".", 1, 1 );
    3. and so on
    To copy to clipboard, switch view to plain text mode 

    p.s. split returns QStringList, that's why you can assign it right to stringlist, without operator <<
    Qt Code:
    1. QStringList list = ipString.split( "." );
    To copy to clipboard, switch view to plain text mode 

  5. The following 3 users say thank you to borisbn for this useful post:

    Septi (6th July 2010), tablebubble (8th July 2010), Zlatomir (6th July 2010)

  6. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: getting the substring with delimiter

    @borisbn Good point with the split return type, thanks

  7. The following user says thank you to Zlatomir for this useful post:

    tablebubble (8th July 2010)

Similar Threads

  1. Highlighting substring problem
    By chandan in forum Newbie
    Replies: 1
    Last Post: 18th April 2010, 17:01
  2. QcomboBox delimiter
    By user_mail07 in forum Qt Programming
    Replies: 8
    Last Post: 2nd December 2007, 10:20
  3. How to check if a string starts with a substring?
    By lni in forum Qt Programming
    Replies: 3
    Last Post: 18th April 2007, 00:36
  4. Replies: 2
    Last Post: 10th February 2006, 12:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.