这些特殊字符在Java中意味着什么? [英] What do these special characters mean in Java?
本文介绍了这些特殊字符在Java中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在查看一些jdk代码。我找到了这些角色。有人可以向我解释这些是什么意思。
I was looking at some of the jdk code. I found these characters. Could someone explain to me what do these mean.
public static String quote(String s) {
int slashEIndex = s.indexOf("\\E"); // What does this mean. Is this a special char in java. if so what does this do.
if (slashEIndex == -1)
return "\\Q" + s + "\\E";
StringBuilder sb = new StringBuilder(s.length() * 2);
sb.append("\\Q");
slashEIndex = 0;
int current = 0;
while ((slashEIndex = s.indexOf("\\E", current)) != -1) {
sb.append(s.substring(current, slashEIndex));
current = slashEIndex + 2;
sb.append("\\E\\\\E\\Q");
}
sb.append(s.substring(current, s.length()));
sb.append("\\E");
return sb.toString();
}
从上面的代码示例中,我能够弄清楚发生了什么method查找\的出现次数并将它们转换为\E和\Q。有人可以解释为什么会这样。
From the above code example I was able to figure out what's happening as in the method finds the occurrences of \ and converts them to \E and \Q. Could someone explain why that's the case.
有关此方法的更多上下文,我正在研究jdk 1.6中的Pattern.quote()方法
For more context on this method, I was looking into the Pattern.quote() method from jdk 1.6
推荐答案
\ Q
和 \ E
正是 Pattern.quote()
确实,即返回指定字符串的文字模式字符串。
有关详细信息,请参阅此链接:
http://docs.oracle.com/javase/1.5.0/docs/api/java/util/regex/Pattern。 html
这篇关于这些特殊字符在Java中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文