String str = in.readLine();
str.replaceAll("*#*", ",");
他想将客户端发送的str中的所有"*#*"直接换换成",",以便将来转来数组,可是执行到这一句即出错?我试了直接用String[] sub = str.split("*#*");也会报错?难道*#*有特殊作用?不能进行替换吗?急!!!

解决方案 »

  1.   

    我把代码改成
    String str = in.readLine();
    String mystr=str.replaceAll("*#*", ",");也不得行????报错
      

  2.   

    *不行    楼主看下这个
    public class Test
    {
    String str="*#**##*#*#111";
    public Test()
    {
    str=str.replaceAll("\\*#\\*",",");
    System.out.println(str);
    }
    public static void main(String [] args)
    {
    new Test();
    }
    }
      

  3.   

    replace(char,char),只能替换一个字符还是用replaceAll吧 String s = "*#*sdkfjosdf";

    s=s.replaceAll("\\*#\\*",",");
    System.out.println(s);
      

  4.   

    在1.4版本的api中replaceAll方法是这样定义的
    public String replaceAll(String regex,
                             String replacement)
    第一个参数是要匹配的正则表达式,*#*不是你需要的正则表达式的的写法
      

  5.   

    public class ghyghost { public static void main(String[] args) {String ghy="ghyghost*#*s csdn";
    System.out.print(ghy.replaceAll("\\*#\\*","\'"));
    }}
      

  6.   

    String str = in.readLine();
    while(str.lastIndexOf("*#*") > -1) {
    str = str.replace("*#*", ",");
    }