Try to find the string "abc\ntest"
inside a QStringList (with indexOf). "\n"
are two normal characters in the search-string.
If i change the search-pattern into "abc\\ntest"
I find the string.
Why?
Asked
Active
Viewed 28 times
2

Martin Bonner supports Monica
- 28,528
- 3
- 51
- 88

sh2623
- 31
- 1
-
sorry, one error : If i change the string in "abc\\ntest" if find the string – sh2623 Mar 18 '19 at 16:06
-
Despite the downvote, this is not a bad question. You have to know the phrase "escape sequence" to find the answer. The tldr is that your C++ compiler treats `"\n" `as a *single* character (the newline character). Similarly `"\\"` is a single character - the backslash character. – Martin Bonner supports Monica Mar 18 '19 at 16:11
-
... and for a very similar reason, the text formatter in Stack Overflow questions treats backslash specially ... unless they are inside back-ticks (which also make them look like code). – Martin Bonner supports Monica Mar 18 '19 at 16:12