Replacement of JavaScript strings

Source: Internet
Author: User

Parameter description
Findstring target string
Required. specifies a string value to find.
Perform a global search Add a 'G' flag to this parameter and to perform
Case-insensitive search add an 'I'
Flag
Required. Specify the string to be replaced. To perform multiple matching, you need to add a "G" tag. To specify fuzzy match, you need to add an "I" mark

Newstring
Required. specifies the string to replace the found value
From findstring
Required. New Value of the string to be replaced

You can refer to the following implementation for all replacement:

1
VaR teststr =
"Aaabbbcccdddaaa ";
Alert (teststr. Replace (/A/G, 'x '));
Replace all A in the string teststr with x

2
Stringobj. Replace (New
Regexp (oldstring, "GM"), newstring ))
Note:
G of GM indicates global,
M indicates multiline, which can replace all specified strings.

3
VaR teststr =
"Aaabbbcccdddaaa ";
STR = Str. Split ("A"). Join ("X ");
Alert (STR)
;
Replace all A in the string teststr with x

Reference: http://wangyi878750.blog.sohu.com/31370032.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.