A summary of the methods of string-string objects in javascript:

Source: Internet
Author: User

Warm so know the new, can for the teacher. The string object looks at the following method.

1:string.charat (Index) method: Returns the character of the string index.

1 ' Hello '. CharAt (1); 2 "E"

2:string.charcodeat (Index) method: Returns the ASCII code for the character of the string index.

1 ' a '. charCodeAt (0); 2 97

The 3:string.indexof method determines the position of a string in another string (numeric type), and if 1 is returned, it indicates a mismatch, and IndexOf begins to match from the string header

1 ' Hello '. indexOf (' e '); 2 1

The 4:string.lastindexof method determines the position of a string in another string (numeric), and if 1 is returned, it does not match, and IndexOf starts at the end of the string.

1 ' Hello '. lastIndexOf (' e '); 2 1  //Because the position returned is actually from the beginning of the number, the individual to raise the two functions are not different

5:string.concat (string,...); String concatenated, the return value is a new string, but the original string does not change

1 var s= ' abc '; 3 s.concat (' eee '); 4 "Abceee" 5 s 6 "ABC"

6:string.replace (' Sub-string 1 ', ' substring 2 '); String substitution, the string 2 is substituted into a substring 1

7:string.tolowercase () Convert the string to lowercase string.touppercase () converts the string to uppercase

' Aaaeee '. toLocaleLowerCase ();//lowercase "aaaeee" ' aaaaa '. toLocaleUpperCase (); Uppercase "AAAAA"

8:string.formcharcode (numeric); This is a static method of the string object, passing in an ASCII code that returns the character corresponding to the code.

1 String.fromCharCode (); 2 "a"

9: String interception method: Subtring () |   substr () | Slice ()

SUBSTRING (): Pass in two parameters, the first parameter is the starting position, the last parameter is the end position, and the truncated substring is returned. [does not include the end position of the character]

1 ' Hello World ' substring (2,7); 2 "Llo W"

Substr () Method: Pass in two parameters, the first parameter is the starting position, the last parameter is the number of characters to intercept, return the truncated substring

1 ' Hello World ' substr (2,9); 2 "Llo World"

Slice () method: Pass in two parameters, the first argument is the starting position, the last parameter is the end position, and the truncated substring is returned. [Character not including end position] If the 2nd argument is greater than the first parameter, both the return value is empty.

var C = ' The Three Musketeers '; C.slice (4, 9)//' Three ' C.slice (9, 4)//'

10:string.split (delimiter): Splits the string, the return value is an array;

1 ' A|b|c '. Split (' | ') 2 ["A", "B", "C"]

The above is an introduction to some of the built-in methods of the string built-in object mind map.

A summary of the methods of string-string objects in javascript:

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.