Results 1 to 5 of 5

Thread: Tokenizer with QString?

  1. #1
    Join Date
    Sep 2008
    Posts
    38
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Tokenizer with QString?

    hallo everybody,

    there is a funtion in MFC named CStringT::Tokenize,

    how can i do it with QString?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tokenizer with QString?

    What kind of tokenization do you need?

    There is no such thing available in QString anyway but you can achieve similar effect using the split() methods (if the kind of tokenization you need allows it, e.g. tokens limited by whitespaces).

    Otherwise you'll have to implement a tokenization algorithm yourself.
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Sep 2008
    Posts
    38
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tokenizer with QString?

    The original code is like this:
    cstring_a = cstring_b.Tokenize(",. %#", token_postion);
    Problem is the ",. %#",..

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Tokenizer with QString?

    try something like that (untested)
    Qt Code:
    1. QStringList l = someString.split(QRegExp("[,\. %#]"))
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tokenizer with QString?

    If the first character string is a list of token delimiter then what caduel suggested should work, except that he forgot to escape the backslash (does the dot needs to be backslashed inside a set anyway?) :
    Qt Code:
    1. QStringList l = someString.split(QRegExp("[,\\. %#]"))
    To copy to clipboard, switch view to plain text mode 
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 16:26
  2. easiest Way QString can do
    By baray98 in forum Qt Programming
    Replies: 12
    Last Post: 15th April 2008, 20:49
  3. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47
  4. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  5. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 22:10

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.