请问各位高手一个问题就是
如果要替换以下字符串
“/*AAAAAA*/ ”应该怎么办啊?
用replaceAll("/*AAAAAA*/","other")根本就不行啊
是因为编译器忽略/**/中任何字符的关系吗??
各位请帮帮忙 谢过了

解决方案 »

  1.   

    用String.codePointAt()读取它的代码点,然后再替换咋样·?
      

  2.   

    public class Test {
    public static void main(String[] args) {
    String str = "aaa/*AAAAAA*/bbb";
    int index = str.indexOf("/*AAAAAA*/");
    String  strStart = str.substring(0, index);
    String  strEnd = str.substring(index + "/*AAAAAA*/".length());
    str = strStart + "Other" + strEnd;
    System.out.println(str);
    }
    }
      

  3.   

    str.replace(target, replacement);
    因为replace()的两个参数是作为字符序列处理
    而replaceAll()的参数是要考虑正则表达式的
      

  4.   

    试下这样
    replaceAll("\/\*AAAAAA\*\/","other")
      

  5.   

    用果子的写法,再循环到indexOf为-1就可以了。string在这里的处理是怎么考虑的呢,好像欠妥当。
      

  6.   

    public class Test {
    private static String str = "jfkajf/*AAAAAA*/fjlakl/*AAAAAA*/dada";
    public static void main(String[] args) {
    Test t = new Test();
    t.processReplace(str, "/*AAAAAA*/","other");
    }
    public String processReplace(String input,String beReplace,String replace){
    String processedString="";
    int index = input.indexOf(beReplace); 
    if(index>0){
    String start=input.substring(0,index);
    String end = input.substring(index+beReplace.length(),input.length());
    processedString = start+replace+end;
    System.out.println(processReplace(processedString,beReplace,replace));
    }
    return processedString;
    }
    }刚刚测试的一个完整的,你测试下?
      

  7.   

    有那么麻烦么???
    正则表达式写在字符串里的时候转义字符要用双反斜线来标出,如下:
    class Noname6 
    {
    public static void main(String[] args) 
    {
    String s="/*aaa*/111bbb222ccc/*aaa*/333ddd444";
    System.out.println(s.replaceAll("/\\*aaa\\*/","XXX"));
    }
    }