A common method of JS strings string

Source: Internet
Author: User

1. charAt () returns the character at the specified position.


empty string )
In addition: the first character of a string is returned by Str.charat (), without parameters and Str.charat (NaN)

2. charcodeat () returns the Unicode encoding of the character at the specified position.

Str.charcodeat (Index)  
NaN)

3. concat () is used to concatenate two or more strings.

var a = "Hello", B = "Kitty", c = "!";
A.concat (B,C)//function and "+" splicing is no different

4. fromCharCode () accepts a specified Unicode value and returns a string.

 string. fromCharCode (unicode1, Unicode2,..., nuicodex) The method is a static method of String, and the syntax should be String.fromCharCode (). 

5. The indexOf () method returns the location of the first occurrence of the specified string in the string. returns 1 if the match is not reached.

Str.indexof (Searchstr,startindex)  
Searchstr required to indicate a string value that needs to be matched;
startindex Optional, the value range 0 to str.length-1, omit the default first character to start the search.

6. lastIndexOf () returns the location of the last occurrence of the specified string value, which is searched from behind at the specified position in a string.

Str.indexof (Searchstr,startindex)  
Searchstr required to indicate a string value that needs to be matched;
startindex Optional, the value range 0 to str.length-1, omit the default trailing character to start the search.

7. The match () method retrieves the specified value within a string, or finds a match for one or more regular expressions.

The method is similar to IndexOf () and lastIndexOf (), but it returns the specified value instead of the position of the string.

Str.charcodeat (Index)  
Index is a must parameter, the type is number (0 to str.length-1, otherwise the method returns NaN)
In addition: the first character of a string is returned by Str.charat (), without parameters and Str.charat (NaN)

8. The Replace () method is used to replace other characters with some characters in a string, or to replace a substring that matches a regular expression.

Str.charcodeat (Index)  
Index is a must parameter, the type is number (0 to str.length-1, otherwise the method returns NaN)
In addition: the first character of a string is returned by Str.charat (), without parameters and Str.charat (NaN)

9. The search () method is used to retrieve the substring specified in the string, or to retrieve a substring that matches the regular expression.

Str.charcodeat (Index)  
Index is a must parameter, the type is number (0 to str.length-1, otherwise the method returns NaN)
In addition: the first character of a string is returned by Str.charat (), without parameters and Str.charat (NaN)

The Slice () method extracts a portion of a string and returns the extracted part with a new string.

Str.charcodeat (Index)  
Index is a must parameter, the type is number (0 to str.length-1, otherwise the method returns NaN)
In addition: the first character of a string is returned by Str.charat (), without parameters and Str.charat (NaN)

The split () method is used to split a string into an array of strings.

Str.charcodeat (Index)  
Index is a must parameter, the type is number (0 to str.length-1, otherwise the method returns NaN)
In addition: the first character of a string is returned by Str.charat (), without parameters and Str.charat (NaN)

The substr () method extracts a specified number of characters from the start subscript in a string.

Str.charcodeat (Index)  
Index is a must parameter, the type is number (0 to str.length-1, otherwise the method returns NaN)
In addition: the first character of a string is returned by Str.charat (), without parameters and Str.charat (NaN)

The substring () method is used to extract the character of a string intermediary between two specified subscripts.

Str.charcodeat (Index)  
Index is a must parameter, the type is number (0 to str.length-1, otherwise the method returns NaN)
In addition: the first character of a string is returned by Str.charat (), without parameters and Str.charat (NaN)

tolocaleuppercase () / tolocalelowercase () is used for string conversion case ( only if there are differences in some foreign languages with the methods below )

touppercase () / toLowerCase () for string conversion case

A common method of JS strings string

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.