Results 1 to 3 of 3

Thread: scan text for escape characters

  1. #1
    Join Date
    Aug 2009
    Posts
    122
    Thanks
    74
    Qt products
    Qt4
    Platforms
    Windows

    Question scan text for escape characters

    Hi,

    I need to change escape characters in my text document (for example change every \r to \n). What is the best way to do that using Qt and C++? I don't want to make any assumptions about the format (Win or Mac) while reading in the data.

    I typically use QTextStream and readLine() to read text into QString and then I use replace() to make changes. Here I have two problems:
    1. readLine loses newline characters (line breaks) - main problem
    2. My entire document may be too large to fit in a QString - small problem

    Are there any tricks to replacing escape characters compared to replacing simple letters or numbers?

    Thanks!

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: scan text for escape characters

    Let's be clear here, you want to the replace the single carriage return character or the single line feed character, not the two character escapes you would see in C++ code.

    Are there any tricks to replacing escape characters compared to replacing simple letters or numbers?
    No. Open file (QFile), read bytes (QIODevice::read()), replace characters (QByteArray::replace()), write bytes (QIODevice::write()).

  3. The following user says thank you to ChrisW67 for this useful post:

    timmu (9th August 2012)

  4. #3
    Join Date
    Aug 2009
    Posts
    122
    Thanks
    74
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: scan text for escape characters

    Thank you, ChrisW67.

    Problem solved.
    Last edited by timmu; 9th August 2012 at 10:34.

Similar Threads

  1. Replies: 15
    Last Post: 31st January 2020, 19:25
  2. QString with escape characters
    By Jeffb in forum Newbie
    Replies: 1
    Last Post: 26th April 2010, 15:06
  3. Replies: 1
    Last Post: 14th September 2009, 02:24
  4. Displaying all characters in text edit
    By chadkeck in forum Qt Programming
    Replies: 1
    Last Post: 17th September 2008, 02:48
  5. Vista - Scan System Hardware?
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2008, 19:07

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.