Blog

JavaScript - str_replace

function str_replace(search, replace, subject) {
    var re = new RegExp(search,"g");
    return subject.replace(re, replace);
}

Example:

var search = "Hello";
var replace = "Bye";
var subject = "Hello World, Hello David";
var x = str_replace(search, replace, subject);
alert(x); // Bye World, Bye David
Categorieën
JavaScript
Zoeken