The syntax of the replace method is: stringObj.replace(rgExp, replaceText) where stringObj is a string (string), reExp can be a regular expression object (RegExp) or is a string, and replaceText is a replacement for the found string. . In order to help everyone understand better, let’s give a simple example below
Js code
Zhonggu" For "China"
the value has not changed
China");
If you are smarter than me, after reading the above example, you will find that the second typo "Zhonggu" does not change has not been replaced with "China", we can execute the secondary replace method to replace the second typo "Zhonggu". The program is improved as follows:
Js code
The value of "Zhonggu" is "China"
has not changed
China");
China");
We can think about it carefully, if there are N^Nth power typos, do we also need to execute N^Nth power replace method to replace the typos? Oh, don't be afraid, there is a regular expression? There is no need to execute the replace method after the formula. The code after the program is improved is as follows
.
Js code
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn