PDA

View Full Version : Carriage Return in QString



incapacitant
14th May 2006, 16:26
I have a QTextEdit that contains a carriage return.
I convert to QString :


Message = qMessage->toPlainText();

Then I am unable to remove the carriage return from the QString and replace it with a space character.

I tried :
- to split the string with regexp "\r"
- the stupid

for ( int i = 0; i < Message.size(); i++ )
if ( ( Message[i] == QChar(10) ) && ( Message[i+1] == QChar(13) ) ) {
Message[i] = ' ';
Message[i+1] = ' ';
}

- Message.replace("\r"," ");
- Message.replace(QRegExp("\r"), " "); even with "0x0D"

All fails.

At the end of the modification I copy back my QString to a QTextEdit to display the result and the carriage return is still there. No way to remove it.

jacek
14th May 2006, 16:38
Try searching for '\n'.

incapacitant
14th May 2006, 17:10
Of course it works, jacek is not expert but god.

jimadamthwaite
15th June 2006, 20:19
It may be worth detecting the sequence CR,LF as well.

raedbenz
9th October 2010, 09:29
#ifdef linux
QString myNewLine = "\n";
#endif
#ifdef WIN32
QString myNewLine = "\n\r";
#endif
#ifdef __APPLE__
QString myNewLine = "\n";
#endif

Lykurg
9th October 2010, 10:09
Ehm, the thread is 4 (in letters four) years old! But anyway, whats the goal by defining myNewLine? On windows there might be also files which only use new line character. And QTextEdit transforms the different line breakings to "\n", so no need to distinguish.

ChrisW67
10th October 2010, 23:19
Line 5 has the characters the wrong way around also.

StefanQtNutzer
2nd December 2010, 09:18
Hi Lykurg.

Is it possible to dispose QtextEdti to do NOT the transormation from \r\n to \n?