In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I would like to share with you the relevant knowledge about how javascript modifies a certain value of a string. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article.
In JavaScript, you can use the replace () method to modify a value of a string, which is used to replace some characters in a string with other characters, or to replace a substring that matches a regular expression, with the syntax of "string .replace (regexp/substr, replacement value or function)".
The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.
How javascript modifies a value of a string
The replace () method is used to replace some characters in a string with other characters, or to replace a substring that matches a regular expression.
Grammar
StringObject.replace (regexp/substr,replacement)
Parameter description
Regexp/substr is required. A RegExp object that specifies the substring or the schema to replace. If the value is a string, it is treated as the direct text pattern to retrieve, rather than being first converted to a RegExp object.
Replacement is required. A string value. Specifies the function that replaces the text or generates the alternate text.
Return value
A new string is obtained after replacing the first match or all matches of regexp with replacement.
Description
The replace () method of the string stringObject performs the find and replace operation. It looks for substrings that match regexp in stringObject and replaces them with replacement. If regexp has the global flag g, then the replace () method replaces all matching substrings. Otherwise, it replaces only the first matching substring.
Replacement can be either a string or a function. If it is a string, each match will be replaced by a string. But the $character in replacement has a specific meaning. As shown in the following table, it indicates that the string obtained from the pattern match will be used for replacement.
Examples are as follows:
Var str= "Visit city!" [xss_clean] (str.replace (/ city/, "School"))
Output result:
Visit School!
That's all about the article "how javascript modifies a value of a string". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.