1

I use this text text\r2. And I want to print this in debug and get result:

text\r2

but I get this:

text
2
user
  • 87
  • 1
  • 8
  • Just out of curiosity, what OS are you using? On Unix systems (including Mac), you should get `2ext` -- `\r` moves to the beginning of the line, without moving down a line like the return key does. – SilverWolf Mar 15 '18 at 15:52

2 Answers2

2

Try to escape the backslash with another backslash: text\\r2.

The \r will otherwise be interpreted as a line break.

Alexander
  • 87
  • 1
  • 6
1

\r in a String literal is a special character and represents a carriage return

See Special Characters in String Literals


String literals can include the following special characters:

 * The escaped special characters \0 (null character), \\ (backslash), \t (horizontal tab), \n (line feed), \r (carriage return), \" (double quotation mark) and \' (single quotation mark)
 * An arbitrary Unicode scalar, written as \u{n}, where n is a 1–8 digit hexadecimal number with a value equal to a valid Unicode code point (Unicode is discussed in Unicode below)

If you want to use in a String Literal a backslash you have to escape it using \\.

So you'll have to write

print("text\\r2") 

to get text\r2

andih
  • 5,570
  • 3
  • 26
  • 36
  • I understand this is not welcomed by the community. But could you please help with this problem. I just don't know what to do. Thanks! - https://stackoverflow.com/questions/69851479/audio-files-wont-play-with-airpods-pro-on-ios-15 – user Nov 12 '21 at 20:35