JavaScript string processing

Source: Internet
Author: User

String processing

1. Connection string:

1) connector +:

2) Connection Assignment + =:

3) Connection letter concat ()

2. find sub-string position indexOf()

1) whether a given string exists in the specified string ( first occurrence )

2) Usage str.indexof (SUBSTR);

3) The presence returns a value greater than or equal to 0 ; return -1

3. find the specified position character Chatat (n)

1) search for characters in a specified position in a string

2) Usage str.charat (n);

3) index starting from 0

4. confirm where the substring last appears in the string lastIndexOf()

1) Get the last position of the substring in the string

2) usage var n=str.lastindexof (ARGSTR)

3) The presence returns a value greater than or equal to 0 ; return -1

5. intercept the first substring of a string substring()

1) Gets the first substring of a specified length of a string

2) usage var substr=str.substring (Gegin[,end]);

3) when begin>length-1 , if end>length-1, the interception is an empty string;

4) If the Begin and end values are reasonable and begin>end, begin and End Interchange

5) Difference from substr(start,length)

6. extracting part of a string slice()

1) Extracts a part of the string and returns a new string

2) usage var substr=str.slice (Begin[,end])

3) Difference from substring ( ): when begin>length-1 , the empty string is returned; when begin>end , return empty string

7. splitting a string into a string array split()

1) Divide the string into substrings

2) usage var array=str.split (s);--s as a separator (can be any combination of strings)

JavaScript string processing

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.