One of the JS summaries: How to invoke a string

Source: Internet
Author: User

Methods for invoking strings:
var s= "Hello, World";
document.write (S.charat (0)); First character
document.write (S.charat (s.length-1)); Last character
document.write (s.substring (1,4)); 2nd to 4th character
document.write (S.slice (-3)); Last 3 character (s)
document.write (S.indexof ("L")); Position of the first occurrence of the character L
document.write (S.lastindexof ("L")); The position of the last occurrence of the character L
document.write (S.indexof ("L", 3)); Position of the character L for the first occurrence after position 3 and after
document.write (S.split (",")); Use, Separate strings
document.write (S.replace ("H", "H")); Full-text character substitution
document.write (S.touppercase ()); Replace with uppercase

In addition to using the Charat () method, you can access a single character in a string by [].

S= "Hello,world";
S[0]; First character
s[s.length-1];//last character

One of the JS summaries: How to invoke a 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.