Results 1 to 7 of 7

Thread: Split QString only at unescaped slash

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Qt products
    Qt5
    Platforms
    MacOS X
    Thanks
    13
    Thanked 153 Times in 150 Posts

    Default Re: Split QString only at unescaped slash

    Qt doesn't require double backslashes, it's the C++ compiler that requires the double backslashes in quoted strings. If you are getting the string from user input or reading from a file, double backslashes are not required. This example reads the string from the file:
    Qt Code:
    1. QFile f("/Users/jefft/test.txt");
    2. f.open(QFile::ReadOnly);
    3. QString str = f.readLine();
    4. f.close();
    5. QRegularExpression re("\\/(?<!\\\\\\/)");
    6. QStringList strlist = str.split(re);
    To copy to clipboard, switch view to plain text mode 
    Where the test.txt file contains:

    hello/world/how\/are/you

    This should be the same if your text is coming from a QLineEdit, etc.

  2. The following user says thank you to jefftee for this useful post:

    QphiuchuS (20th January 2015)

Similar Threads

  1. Replies: 7
    Last Post: 6th February 2017, 20:10
  2. Replies: 1
    Last Post: 28th April 2013, 11:47
  3. Replies: 5
    Last Post: 26th January 2012, 15:04
  4. Replies: 2
    Last Post: 9th January 2009, 20:49
  5. QString split()
    By ShaChris23 in forum Newbie
    Replies: 4
    Last Post: 3rd May 2007, 05: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
  •  
Qt is a trademark of The Qt Company.