(I am not sure what happened but I lost my reply when I try to reply to this message this moring...)
Hi!

Originally Posted by
high_flyer
Do you mean \n to "newline" or to carriage return - '\r' or something else?
Since \n IS newline.
Not when it's actually a backslash followed by a "n"... I want to convert strings I read from a file so that when I see a backslash followed by a "n" I convert it to a newline and if I see a backslash followed by a backslash I convert that to a single backslash.
Does this do what you want?
test = test.replace(esc2,esc);
QString esc2 = '\\';
QString esc = "'\'";
test = test.replace(esc2,esc);
To copy to clipboard, switch view to plain text mode
What I came up with to do it currently looks something like this:
strt.
replace(QString("\\\\"),
QString("<SOMETHING_THAT_CANT_BE_IN_THE_FILE>"));
strt.
replace(QString("<SOMETHING_THAT_CANT_BE_IN_THE_FILE>"),
QString("\\"));
strt.replace(QString("\\\\"), QString("<SOMETHING_THAT_CANT_BE_IN_THE_FILE>"));
strt.replace(QString("\\n"), QString("\n"));
strt.replace(QString("<SOMETHING_THAT_CANT_BE_IN_THE_FILE>"), QString("\\"));
To copy to clipboard, switch view to plain text mode
Because of restrictions imposed by the format of the file I read this from it's actually pretty easy to find to replace <SOMETHING_THAT_CANT_BE_IN_THE_FILE> with.
I have read that though I could actually directly pass the strings to replace() instead of the QString it's actually preferrable to use QString there, is that right?
If I had to do more than these two remapings though I guess I would have eventually have no choice but to decode the string character by character and to rebuild it though otherwise it would eventually be too slow to do this in multiple passes...
I was hoping that there would be something in Qt that does that when I saw Qt::escape... I could have sworn I read about something that did it (something like unbackslash?) but I can't seem to find where I found it and it's not unbackslash apparently...
Thank you!
Nick
Bookmarks