首页 > 编程语言 > 详细

实现JavaScript中String对象的replaceAll()函数

时间:2015-03-26 17:48:11      阅读:299      评论:0      收藏:0      [点我收藏+]

JavaScript脚本语言中,大家对String对象使用replace()函数肯定不陌生,但是却没有如Java语言一般有replaceAll()方法,但是在使用中,又不可避免的会使用到,这种时候当然只有我们程序员自己来动手咯!!

/**
 * Author Joyce.Luo 10:19:54 prepared in 2015.01.05
 * JavaScript language Methods: replaceAll(), based on the replace() method to realize
 * @param {} rgExp The need to replace the string or regular object
 * @param {} replaceText The string matching to replace the string
 * @return {} Returns a new string replacement
 */
String.prototype.replaceAll = function(rgExp, replaceText){
    return this.replace(new RegExp(rgExp,'gm'), replaceText);
};

效果简单明了。。。。。

实现JavaScript中String对象的replaceAll()函数

原文:http://blog.csdn.net/luo201227/article/details/44650953

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!