且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

替换字符串中部分字符串,java

更新时间:2022-09-06 10:08:36

public  String replace(String from, String to, String source) 
     {   
        if (source == null || from == null || to == null)   
            return null;   
        StringBuffer bf = new StringBuffer("");   
        int index = -1;   
        while ((index = source.indexOf(from)) != -1) 
        {   
            bf.append(source.substring(0, index) + to);   
            source = source.substring(index + from.length());   
            index = source.indexOf(from);   
        }   
        bf.append(source);   
        return bf.toString();   
    }


http://slddyb.blog.51cto.com/2294765/409676