String Method Summary

Source: Internet
Author: User

One, character method

charAt: Returns the character at the specified position.

var str= "ABCDEFG";//undefinedstr[0]//"a" because IE67 does not support this notation Str.charat (0)//"a"

charCodeAt: Returns the Unicode encoding of the character at the specified position.

Second, the string operation method, does not affect the original string, returns the new string

concat: string concatenation--Returns a new string without affecting the original string. More time with "+"

Slice: Extracts a fragment of a string that returns the extracted part. When the argument is negative, the passed negative value is added to the length of the string

substring: Extracts the characters between two specified index numbers in a string. All negative arguments are converted to 0

substr: Extracts the specified number of characters from the starting index number in the string. The negative first argument is prefixed with the length of the string, and the second argument of the negative is converted to 0

var str= "ABCDEFG"//undefinedstr.slice (0,1)//"A" str.substr (0,1)//"A" str//"ABCDEFG" Str.slice ( -3)//"EFG" Str.substring ( -3)//"ABCDEFG" Str.substr ( -3)//"EFG" Str.slice (3,-4)//"Str.slice (0,-4)//" ABC "str.substring (3,-4)/ /"ABC" STR.SUBSTR (3,-4)//""

Trim: Returns a new string after a trailing space has been deleted

trimleft: Remove opening spaces

trimright: Remove trailing spaces

var str= "abc"  //undefinedstr//"abc"  Str.trim ()//"abc" str//"   ABC  " Str.trimleft ()//"ABC  "

Case conversion:

toLowerCase

Tolocallowercase

toUpperCase

tolocaluppercase: A region-specific approach

Three, the string position method

indexOf: Returns the position of the first occurrence of a specified string value in a string.

lastIndexOf: Returns the position in a string at the specified position from the back to the forward search.

Str.indexof (' B ')//1str.lastindexof (' B ')//1

String Method Summary

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.