PDA

View Full Version : scan text for escape characters



timmu
9th August 2012, 06:05
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!

ChrisW67
9th August 2012, 07:15
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()).

timmu
9th August 2012, 09:33
Thank you, ChrisW67.

Problem solved.