嗳,人家说java之中无高手,原来是真的

解决方案 »

  1.   

    * Replaces each substring of this string that matches the given <a
         * href="../util/regex/Pattern.html#sum">regular expression</a> with the
         * given replacement.
    看样子应该可以适用于所有String,substring也是String啊
      

  2.   

    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)));
    }
      

  3.   

    是不是不能替用substring取出来的字符串呀??取出来的还是不是String??是!!So 可以!!!
      

  4.   

    但是我试着替换的时候根本不能成功
    程序没有出问题,编释也成功
    但就好象是替换语句没执行一样
    我也不想用自己写的replaceAll,因为会增加程序的复杂性
      

  5.   

    replaceAll
    就是使用一个字符串替换另一个字符串啊
    只要你原来是一个字符串就可以用的public String replaceAll(String regex,String replacement)函数的返回值就是你要的字符串