首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

急 !在java中怎么把"替换为\"

2012-02-01 
急 !!!在java中如何把替换为\a hrefhttp://sighttp.qq.com/cgi-bin/ target_blank onclickvar

急 !!!在java中如何把"替换为\"
<a href="http://sighttp.qq.com/cgi-bin/"; target=_blank; onclick="var tempSrc='http://sighttp.qq.com/wpa.js?rantime='+Math.random()"></a>

我想把上面的字符串中的"替换为\",怎么做啊?这样替换主要是为了在客户端拼接字符串,比如 "<span style='color:red'>您的qq状态</span>"+"<a href=\"http://sighttp.qq.com/cgi-bin/\"; target=_blank; onclick=\"var tempSrc='http://sighttp.qq.com/wpa.js?rantime='+Math.random()\"></a>"

replaceAll("\"","\\\"")不起作用。

谁有什么好方法交流下。

[解决办法]
replaceAll("\"","\\\\"")不起作用。
[解决办法]
用正则表达式吧。
[解决办法]
下面两个都是用的正则

java:

Java code
public static void main(String[] args) {        String str = "<a href=\"http://sighttp.qq.com/cgi-bin/\"; target=_blank; onclick=\"var tempSrc='http://sighttp.qq.com/wpa.js?rantime='+Math.random()\"> </a>";        System.out.println(str.replaceAll("\\\"", "\\\\\""));    }
[解决办法]
replaceAll("\"","\\\"")
我想你不需要那个All

replace("\"","\\\"")

我想这个就可以了。呵呵。无需正则替换,简单替换足以。

热点排行
Bad Request.