Freecodecamp:search and Replace

Source: Internet
Author: User

Performs a find and replace on a sentence with a given argument and returns a new sentence.

The first parameter is the sentence on which to perform the find and replace.

The second argument is the word that will be replaced (the word before it is replaced).

The third parameter is used to replace the second argument (the replaced word).

Note: Keep the case of the original word when replacing. For example, if you want to replace the word "book" with the word "dog", you should replace it with "dog".

function Myreplace (str, before, after) {  var newstr = "";   if (Before[0] = = = Before[0].touppercase ()    ) {= After[0].touppercase () + after.slice (1);  }   = str.replace (before,after);     return Newstr;} Myreplace ("A quick brown fox jumped over the lazy dog", "jumped", "leaped");

Freecodecamp:search and Replace

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.