java,php,asp.net,linux,javascript,mysql,mssql,oracle,编程

替换字符串

转载请注明:http://www.pmjava.com/Article/ShowInfo.asp?ID=56584
**
   * 替换字符串
   *
   *
@param from String 原始字符串 * @param to String 目标字符串
   *
@param source String 母字符串 * @return String 替换后的字符串
  
*/
 
public static 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();
  }

posted on 2009-06-10 21:25 rrong_m 阅读(94) 评论(0)  编辑  收藏

<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

随笔档案

文章分类

文章档案

java编程

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜