How to detect escape sequence in a user-typed string [solved]
-
I'm just curious if there is a trick for interpreting escape sequences in a TextField.
In Qt's IDE, I can do something like this:
@QString x = "hello "bob"";@
The compile will preprocess the escape sequences so the output is:
@hello "bob"@
Which is great. But if I have a situation where the user types a string into a Qt textfield is there a simple solution for converting the string's escape sequences. So if I wanted to type this into the field:
@line 1\nline 2\nline 3@
Is there a easy way for QString to detect the escape sequence? Or do I have to parse the string myself in code and reconstruct it with the escape sequences?
-
Hi,
If you use QTextEdit then "toPlainText()":http://doc.qt.io/qt-5/qtextedit.html#plainText-prop gives the text as it is.
-
-
Rondog, thats the answer I was looking for.
I had done this exact thing by splitting the string up and rebuiding the string. Your solution is much better!
I am learning that QString has all kinds of convenient ways of manipulating strings. You just brought a new one to my attention. Thanks!
-
Hi,
A regular expression might help you write less code for the replacements