Java 所有转义字符是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1367322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 11:13:53  来源:igfitidea点击:

What are all the escape characters?

javastringescaping

提问by izb

I know some of the escape characters in Java, e.g.

我知道一些 Java 中的转义字符,例如

\n : Newline
\r : Carriage return
\t : Tab
\ : Backslash
...

Is there a complete list somewhere?

某处有完整的清单吗?

采纳答案by rtperson

You can find the full list here.

您可以在此处找到完整列表。

  • \tInsert a tab in the text at this point.
  • \bInsert a backspace in the text at this point.
  • \nInsert a newline in the text at this point.
  • \rInsert a carriage return in the text at this point.
  • \fInsert a formfeed in the text at this point.
  • \'Insert a single quote character in the text at this point.
  • \"Insert a double quote character in the text at this point.
  • \\Insert a backslash character in the text at this point.
  • \t此时在文本中插入一个制表符。
  • \b此时在文本中插入一个退格。
  • \n此时在文本中插入一个换行符。
  • \r此时在文本中插入一个回车。
  • \f此时在文本中插入换页。
  • \'此时在文本中插入一个单引号字符。
  • \"此时在文本中插入一个双引号字符。
  • \\此时在文本中插入一个反斜杠字符。

回答by Ehryk

Java Escape Sequences:

\u{0000-FFFF}  /* Unicode [Basic Multilingual Plane only, see below] hex value 
                  does not handle unicode values higher than 0xFFFF (65535),
                  the high surrogate has to be separate: \uD852\uDF62
                  Four hex characters only (no variable width) */
\b             /* \u0008: backspace (BS) */
\t             /* \u0009: horizontal tab (HT) */
\n             /* \u000a: linefeed (LF) */
\f             /* \u000c: form feed (FF) */
\r             /* \u000d: carriage return (CR) */
\"             /* \u0022: double quote (") */
\'             /* \u0027: single quote (') */
\             /* \u005c: backslash (\) */
\{0-377}       /* \u0000 to \u00ff: from octal value 
                  1 to 3 octal digits (variable width) */

The Basic Multilingual Planeis the unicode values from 0x0000 - 0xFFFF (0 - 65535). Additional planes can only be specified in Java by multiple characters: the egyptian heiroglyph A054 (laying down dude) is U+1303F/ 𓀿and would have to be broken into "\uD80C\uDC3F"(UTF-16) for Java strings. Some other languages support higher planes with "\U0001303F".

所述基本多语种平面是从0x0000的Unicode值- 0xFFFF的(0 - 65535)。在 Java 中只能通过多个字符指定额外的平面:埃及的象形文字 A054(躺下的家伙)是U+1303F/𓀿并且"\uD80C\uDC3F"对于 Java 字符串必须分成(UTF-16)。其他一些语言通过"\U0001303F".

回答by manisha mulchandani

Yes, below is a link of docs.Oracle where you can find complete list of escape characters in Java.

是的,下面是 docs.Oracle 的链接,您可以在其中找到 Java 中转义字符的完整列表。

Escape characters are always preceded with "\"and used to perform some specific task like go to next line etc.

转义字符总是以“\”开头,用于执行某些特定任务,例如转到下一行等。

For more Details on Escape Character Refer following link:

有关转义字符的更多详细信息,请参阅以下链接:

https://docs.oracle.com/javase/tutorial/java/data/characters.html

https://docs.oracle.com/javase/tutorial/java/data/characters.html

回答by Hemin

These are escape characters which are used to manipulate string.

这些是用于操作字符串的转义字符。

\t  Insert a tab in the text at this point.
\b  Insert a backspace in the text at this point.
\n  Insert a newline in the text at this point.
\r  Insert a carriage return in the text at this point.
\f  Insert a form feed in the text at this point.
\'  Insert a single quote character in the text at this point.
\"  Insert a double quote character in the text at this point.
\  Insert a backslash character in the text at this point.

Read more about them from here.

从这里阅读更多关于它们的信息。

http://docs.oracle.com/javase/tutorial/java/data/characters.html

http://docs.oracle.com/javase/tutorial/java/data/characters.html