public String replaceAll(String regex,
String replacement)Replaces each substring of this string that matches the given regular expression with the given replacement.
An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression Pattern.compile(regex).matcher(str).replaceAll(repl)Parameters:
regex - the regular expression to which this string is to be matched
Returns:
The resulting String
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
Since:
1.4
See Also:
Pattern
String replacement)Replaces each substring of this string that matches the given regular expression with the given replacement.
An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression Pattern.compile(regex).matcher(str).replaceAll(repl)Parameters:
regex - the regular expression to which this string is to be matched
Returns:
The resulting String
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
Since:
1.4
See Also:
Pattern
解决方案 »
- 新手求教jsp标签问题
- 关于如何传递一个值到另一个网站的页面,并让该网页自动提交
- struts在JSP页面<form action="/user.do?method=edit&page=1" 提交可以得到page的值吗?
- javax.mail.AuthenticationFailedException错误,请高手们帮帮忙
- 请大家看一下这一句代码显示的错误是什么原因?
- s2sh框架同时访问2个数据库。
- 为什么在安装Tomcat时,安装程序一直停在using jvm这里,我的系统是windows2003?
- 调用动态库.so
- 针对Ext的highchart做的饼图的问题,求大神
- expected at least 1 bean which qualifies as autowire candidate. 应该是没有创建bean?
- 使用jstl标签,标签资源定位问题:
- jstl和el同时使用会出错吗,头痛
可是没有效果
呵呵,刚学java不久,不知道说的对不对!
String str = "aaa\"bbb";
System.out.println(str);
System.out.println(str.replaceAll("\\Q\"\\E", "\\\\"));
}
* 字符串替换方法,用来替换字符串,该复发把可以替换所有的字符串
*
* @param str
* 字符串表达式包含要替代的子字符串
* @param srcString
* 被搜索的子字符串
* @param objString
* 用于替换的子字符串
* @return 被替换后的字符串
*/
public static String replace(String str, String find, String replaceWith) {
return str.replaceAll("\\Q" + find + "\\E", replaceWith);
}
System.out.println(str);
System.out.println(str.replaceAll("\"", "\\\\\""));