some_string.replace(char oldchar,char newchar);这个函数只能用于字符啊,你使用字符串当然不行!!!!如果要用replaceFirst(String oldstring,String newstring);
还是会出错的,因为String的替换用到了正则表达式,你可以看看java.util.regex包。如果不想学上面提到的那些东西,你只好自己写一个函数啦!

解决方案 »

  1.   

    楼上说的对,我也劝你自己新写一个JAVA文件,把里面常用的函数设为static的。
      

  2.   

    public static String replace(String str, String old, String news)
    {
    if(str == null)
    return str;
    int idx = 0;
    if((idx = str.indexOf(old, idx)) >= 0)
    str = str.substring(0, idx) + news + str.substring(idx + old.length());
    return str;
    }

    public static String replaceAll(String str, String old, String news)
    {
    if(str == null)
    return str;
    int begin = 0;
    int idx = 0;
    int len = old.length();
    StringBuffer buf = new StringBuffer();
    while((idx = str.indexOf(old, begin)) >= 0) 
    {
    buf.append(str.substring(begin, idx));
    buf.append(news);
    begin = idx + len;
    }

    return new String(buf.append(str.substring(begin)));
    }