Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 实战错误讨论  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:关于字符串替换的一个怪现象 [Re:snowbird2005]
snowbird2005

米兰大脑



发贴: 72
积分: 10
于 2005-06-10 22:08 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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.




话题树型展开
人气 标题 作者 字数 发贴时间
12734 关于字符串替换的一个怪现象 snowbird2005 450 2005-06-09 23:06
10528 Re:关于字符串替换的一个怪现象 why 616 2005-06-09 23:12
11236 Re:关于字符串替换的一个怪现象 snowbird2005 81 2005-06-09 23:54
10537 Re:关于字符串替换的一个怪现象 why 99 2005-06-10 00:04
11180 Re:关于字符串替换的一个怪现象 snowbird2005 52 2005-06-10 00:31
10428 Re:关于字符串替换的一个怪现象 why 212 2005-06-10 00:56
10544 Re:关于字符串替换的一个怪现象 mesocool 49 2005-06-10 01:13
11251 Re:关于字符串替换的一个怪现象 snowbird2005 203 2005-06-10 19:59
10385 Re:关于字符串替换的一个怪现象 why 469 2005-06-10 21:08
11482 Re:关于字符串替换的一个怪现象 snowbird2005 832 2005-06-10 22:08

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923