问题描述
在Java中, \'
表示单引号(单引号)字符, \
In Java, \'
denotes a single quotation mark (single quote) character, and \"
denotes a double quotation mark (double quote) character.
所以, String s =I\'ma human。; $
So, String s = "I\'m a human.";
works well.
但是, String s =我是人类。
同样, char c ='\';
code> char c ='';
Likewise, char c = '\"';
works, but char c = '"';
also works.
在Java中,哪个更好用? ,像 style =font-family:'Arial Unicode MS';
这样的东西更常见(对于这样的标签,我认为这是使用引号的唯一方法) ,但在Java中,我通常看到人们使用转义字符,例如I \'ma human。
In Java, which is better to use? In HTML or CSS, things like style="font-family:'Arial Unicode MS';"
are more often (and for such tags, I think it's the only way to use quotation marks), but in Java, I usually saw people use escape characters like "I\'m a human."
推荐答案
您不需要转义字符串中的'
字符(包含在),并且不必在char中包含
字符(包含在
'
中) 。
You don't need to escape the '
character in a String (wrapped in "
), and you don't have to escape a "
character in a char (wrapped in '
).
这篇关于在Java中,我应该转义单引号(')在字符串(双引号)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!