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,534
    Thanks
    13
    Thanked 1,576 Times in 1,505 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 09:34.

Similar Threads

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

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.