JavaScript string method

Source: Internet
Author: User

Str= ' I am a string of strings '

CharAt ()//Get a whole string of strings one of which is a substring

Value range: 0~ string Length-1

Alert (Str.charat ())//I do not write anything in parentheses when the default is No. 0

Alert (Str.charat (4))//character

Alert (Str.sharat (10))//empty parentheses have a value beyond the length of the string and nothing can be played out

Alert (Str.sharat (-2))//null above the legal length of the string, nothing can be played out

---------------------------

Sharcodeat ()//Get character corresponding Unicode encoding 0~9 48~57/a~z 65~90/a~z 97~122

Value range: 0~ string Length-1

Alert (Str.sharcodeat ())//25105 ' I ' in the Unicode code brackets and the default is NO. 0

Alert (Str.sharcodeat ()) Alert (Str.sharcodeat (-5))//null

---------------------------

String.fromCharCode ()//return the corresponding string according to character set encoding

Alert (String.fromCharCode (25105))//' I '

Alert (String.fromCharCode (25105,26153))//' I am '

Alert (String.fromCharCode (25105,26153). Length)//2

---------------------------

IndexOf ()//To find the corresponding subscript from left to right according to the substring of the string

Alert (Str.indexof (' one '))//2 characters number the sub-character ' one ' in STR is 2

Alert (Str.indexof (' string ', 4))//6 The second parameter is determined from the beginning of the first search, starting from the fourth ' word ' to find the ' string ' subscript is 6

Alert (Str.indexof (' String ',-5))//3 when the second value is negative, the default is to start with the No. 0 one.

Alert (Str.indexof (' A string '))//2 ' A string ' as a unit, their first occurrence of the position of the subscript is 2

Alert (Str.indexof (' Me ', 20))//-1 exceeds string length, returns-1

Alert (str.indexof (' min '))//-1 characters not present, not found

---------------------------

LastIndexOf ()//based on the sub-characters of the string find the corresponding subscript from right to left to find

Alert (Str.lastindexof (' I '))//0

Alert (Str.laseindexof (' string '))//6

Alert (str.last.IndexOf (' string ', 5))//3 starting from the 5th position from right to left

JavaScript string method

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.