2

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?

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

0 Answers0