/**
    * 将source字符串中的replaceWith字符串替换成replaceTo字符串
    * @param  source String 源字符串
    * @param  replaceWith String源字符串中待替换的字串
    * @param   repalceTo String源字符串中字串欲替换成的字串
    * @return java.lang.String 替换之后的字符串
    */
public static String replaceString(String source, String replaceWith, String replaceTo)
   {
        StringBuffer sb=new StringBuffer();
        int iLength=replaceWith.length();
        int iLastPos=0,iFindPos=0;
        iFindPos=source.indexOf(replaceWith,0);
        while (iFindPos!=-1){
                sb.append(source.substring(iLastPos,iFindPos));
                sb.append(replaceTo);
                iLastPos=iFindPos+iLength;
                iFindPos=source.indexOf(replaceWith,iLastPos);
        }
        sb.append(source.substring(iLastPos,source.length()));
        return sb.toString();
   }

解决方案 »

  1.   

    public class Test
    {
    public static void main(String[] args)
    {
    String s="csdn.net";
    String sChange=s.replaceAll("csdn","classjava");
    System.out.println(sChange);
    }
    }
    这是String类的一个method
    String replaceAll(String s1,string s2)
      

  2.   

    用JTextArea的replaceRange(textString,int start,int end)方法
      

  3.   

    如果不用已有的REPLACE()方法,还有别的方法吗?
    replaceall()方法是如何具体实现的??