View Full Version : Remove \n from QString
arturs
18th April 2015, 22:28
Hi
I have a string with 3 lines.
"ABC"
"ABC"
"ABC"
I want to remove second line.
I can remove all characters in the line but still the line there is.
"ABC"
""
"ABC"
I know in second line there is "\n"
I tried to use remove("\n") but It does not work.
So I need help with the problem.
Regards
Artur
jefftee
18th April 2015, 22:41
I would use QString::split("\n") to created a QStringList of all of the lines. Then you can keep/omit any specific line number or based on QString contents, etc.
ChrisW67
19th April 2015, 08:26
You can remove the blank line by replacing a sequence of two newlines with one newline, see QString::replace().
You could have a look at QString::section() also.
arturs
19th April 2015, 10:32
Hi
Thank you for help.
Today I found Why I have a lot of problems with my QString :)
for example: The QStringList was not created well qDebug show only piece of QString.
so The problem is that in one line of QString there is NULL char :( ( \0).
but It is very hard to remove it :) How to remove it (I tried remve method but without success)
Regards
Artur
ChrisW67
20th April 2015, 08:41
Does
QString result = value.remove(QChar('\0'));
//or
QString result = value.remove(QChar(QChar::Null));
Work?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.