String manipulation of JavaScript

Source: Internet
Author: User

One, capitalize the first letter of the string to return a new string

1.1 Simple notation, capitalize the first letter of a wordString.prototype.firstUpperCase =function){Returnthis[0].touppercase () +This.slice (1); }1.2 Capitalize all words in a string, not first letter lowercaseString.prototype.firstUpperCase =function){ReturnThis.replace (/\b (\w) (\w*)/g,function ($0, $, $) {//\b represents delimiters Span class= "Hljs-comment" >//the first parameter, $ A, represents all substrings (all words) //the second formal parameter represents the string (first letter) that matches within the first parenthesis //the third formal parameter, the string (except for the first letter) that matches within the second parenthesis return $ 1.touppercase () + $2.tolowercase ()}); Another notation string.prototype.firstuppercase = function (return this.tolowercase (). replace (/(|^) [a-z]/g, function (u) { Return U.touppercase ()})              

Second, add a flip function to the string, return a new array
String.prototype.reverse = function () {
Return Array.prototype.reverse.call (This.split (")). Join (')

String manipulation of JavaScript

Related Article

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.