All sample codes for js string replacement_javascript tips
May 16, 2016 pm 05:28 PM/**
* Replace all
* in the string @param obj Original string
* @param str1 Replacement rule
* @param str2 What to replace with
* @return Replaced string
*/
function replaceAll(obj,str1,str2){
var result = obj.replace(eval("/" str1 "/gi"),str2);
return result;
}
例如:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
function replaceAll(obj,str1,str2){
var result = obj.replace(eval("/" str1 "/gi"),str2);
return result;
}
alert(replaceAll("111,222,333",",","|"));
</script>
</head>
<body>
</body>
</html>

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Detailed explanation of the method of converting int type to string in PHP

How to determine whether a Golang string ends with a specified character

How to check if a string starts with a specific character in Golang?

How to repeat a string in python_python repeating string tutorial

How to solve the problem of Chinese garbled characters when converting hexadecimal to string in PHP

PHP String Matching Tips: Avoid Ambiguous Included Expressions

PHP string manipulation: a practical way to effectively remove spaces

PHP techniques for deleting the last two characters of a string
