snowbird2005
米兰大脑
发贴: 72
积分: 10
|
于 2005-06-10 22:08
String newString=str.replaceAll("\\u0024asd\\u0024","hello"); 通过你建议的上面的代码可以成功替代。
以下英文摘自JAVA API帮助文件,参照你的解释,我觉得有点明白它的意思了。 主要就是说:在字符串中要想转义必须使用双反斜杠,否则就是另外一个意思了。谢谢你的解释,非常感谢! Backslashes within string literals in Java source code are interpreted as required by the Java Language Specification as either Unicode escapes or other character escapes. It is therefore necessary to double backslashes in string literals that represent regular expressions to protect them from interpretation by the Java bytecode compiler. The string literal "\b", for example, matches a single backspace character when interpreted as a regular expression, while "\\b" matches a word boundary. The string literal "\(hello\)" is illegal and leads to a compile-time error; in order to match the string (hello) the string literal "\\(hello\\)" must be used.
|