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

解决方案 »

  1.   

    我是用这个函数啊replaceAll("\"", "\\\"")
    可是没有效果
      

  2.   

    replace好象只能替换单个字符,不能替换字符串吧!
    呵呵,刚学java不久,不知道说的对不对!
      

  3.   

    public static void main(String[] args) {
            String str = "aaa\"bbb";
            System.out.println(str);
            System.out.println(str.replaceAll("\\Q\"\\E", "\\\\"));
        }
      

  4.   

    /**
         * 字符串替换方法,用来替换字符串,该复发把可以替换所有的字符串
         * 
         * @param str
         *            字符串表达式包含要替代的子字符串
         * @param srcString
         *            被搜索的子字符串
         * @param objString
         *            用于替换的子字符串
         * @return 被替换后的字符串
         */
        public static String replace(String str, String find, String replaceWith) {
            return str.replaceAll("\\Q" + find + "\\E", replaceWith);
        }
      

  5.   

    String str = "aaa\"bbb";
            System.out.println(str);
            System.out.println(str.replaceAll("\"", "\\\\\""));
      

  6.   

    wts(天胜)的可以实现,不过可以解释一下为什么"\\\\\""去替换"\""而不是"\\\""
      

  7.   

    wts(天胜)不能实现,已经调试过了
      

  8.   

    用acci 码嘛 先全部转换成acci 发现““”的acci就在前面加上’\‘  的acci码