我有一个
String a = "51109965.xml";我需要添加此字符:'\'。所以最后我会得到一个新字符串\ 51109965.xml。
I need to add this character: '\'. So at the end I will get a new string "\51109965.xml".
我正在尝试使用此命令:
I am trying to use this command:
StringBuilder PathBufferXML_new_Provider = new StringBuilder().append("\").append("51109965").append(".xml");但因为此符号'\'保存,我收到一个错误。 如何解决这个问题?
But because this sign '\' is saved, I get an error. How can I solve this issue?
推荐答案在Java中, \ 是一个转义字符。这意味着,它逃脱了以下标志的原始含义。例如,当想要打印具有特殊含义的时,他可以写 System.out.println(\); 。让我们试着找到你的问题的答案,可以重构为:
In Java, \ is an escape character. It means, that it escapes the original meaning of the following sign. For example, when one wants to print " which has a special meaning, he can write System.out.println("\"");. Let's try to find the answer to your question which could be refactored to:
如何打印 \ 在Java中,因为它是一个从特殊字符中逃脱特殊含义的特殊字符?
How can I print \ in Java, as it's a special character which escapes special meaning from the special characters?
System.out.println(\\); 将是您正在寻找的内容,因为它已转义为 \ character。
System.out.println("\\"); will be what you're looking for as it's escaped speacial meaning of a \ character.
...并且非常重要:Java中的字符用单引号表示:'\'而不是\表示 String 对象,其对象的私有字段为 char [] 。
...and a very important thing: characters in Java are represented in single quotes: '\' instead of "\" which represents a String object which has a private field of type char[].
更多推荐
如何添加''\“反斜杠到字符串?
发布评论