[JavaScript] common APIs for string objects

Source: Internet
Author: User
Concat (str1, str2 ,···)

Connection string

Indexof (STR, start)

Returns the position where STR appears for the first time in the string.

 
VaRSTR = "Hello World"; Str. indexof ("Hello ");//0Str. indexof ("O", 5 );//7Str. indexof ("world ");//-1
Lastindexof (STR, start)

Returns the position of STR in the string.

VaRSTR = "Hello World"; Str. lastindexof ("Hello ");//0Str. lastindexof ("O", 3 );//-1Str. lastindexof ("O", 5 );//4
Replace (Regexp/substr, replacement)

In a string, replace some characters with other characters, or replace a string that matches the regular expression.

 
VaRSTR = "I is Allen ."; Str. Replace ("Is", "am ");//"I am Allen ."
Slice (START, end)

Returns a string segment.

VaRSTR = "I am Jack ."; Str. Slice (3, 7 );//"M ja"Str. Slice (3 );//"M jack ."Str. Slice (3,-3 );//"M ja"
Split (separator, limit)

Splits a string into substrings and returns the result as a string array.

 
VaRSTR = "Hello World"; Str. Split ("");//["Hello", "world"]Str. Split ("", 1 );//["Hello"]
Substr (START, lenght)

Returns a string of the specified length starting from the specified position.

VaRSTR = "How do you do? "; Str. substr (4, 2 );//"Do"Str. substr (4 );//"Do you do? "Str. substr (4, 0 );//""Str. substr (4,-1 );//""Str. substr (-3 );//"Do? "
Substring (START, end)

Returns the string at the specified position in the string object, including the start character, but not the end character.

 
VaRSTR = "How do you do? "; Str. substring (0, 3 );//"How"
Tolowercase ()

Converts a string to lowercase.

Touppercase ()

Converts a string to uppercase.

 
VaRSTR = "How do you do? "; Str. tolowercase ();//"How do you do? "Str. touppercase ();//"How do you do? "

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.