The string operator of JS

Source: Internet
Author: User
Tags string methods

1. Character method

// the character ' Zhangamie ' of the output index value . charAt (2)  //  "a"//"a"//  output code A's Ascill code is the"Zhangamie". charCodeAt (2)  ///string.fromcharcode ($)  //  ' a '

2. String methods

Concat, slice, substr, substring do not affect the original string
 //  connect   var  name = ' Zhang ' ;  var  newName = Name.concat (' amie '  // zhang  console.log (newName ) // zhang amie  //  intercept string  // slice, substr, substring the first parameter is the index of the start position  // slice and substr can accept negative numbers (automatically converted to length-/negative numbers/)  // slice, substring the second parameter is the end index, not the match to the end  // substr The second parameter is the number of captures, not the match to the end  

3. String Position method

IndexOf and LastIndexOf, the first argument to match the string, the second parameter is the location to start looking for

// 5

4.trim clear space before and after

'    z  hangamie     '. Trim ()  //"z  hangamie"

5. Match

var name = ' Cat,bat,sat,fat 'name.match (/.at/g)  //["Cat", "bat", "sat", "fat "]//8 indexof is not accepted regexp//" ABC,ABC,ABC,ABC "does not affect the meta-string

The string operator of JS

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.