Common methods of String in Javascript-example analysis-javascript skills

Source: Internet
Author: User
This article mainly introduces the common methods of String in Javascript, and analyzes the common character conversion, truncation, and segmentation techniques of String, for more information about how to use String in Javascript, see the following example. Share it with you for your reference. The details are as follows:

// Length attribute: obtains the number of characters in a string. Var s = 'Love is like a gust of wind'; alert (s. length); // charAt (index) method: Gets the character at the specified index position. The index starts from 0. var s1 = 'I don't miss you anymore'; alert (s1.charAt (4 )); /// // indexOf ('e', startIndex) method: obtain the position where the specified string appears for the first time. StartIndex indicates the number of times to start searching. Var s2 = 'after knowing it, I think it has passed another autumn'; alert (s2.indexOf ('ta', 3); // 6 // split ('delimiter ', returns a string as an array based on the delimiter. // Limit indicates the maximum length of the array to be returned (customizable ). Var s3 = 'horse | in the rivers and lakes | kill '; alert (s3.split (' | ', 2); // use | as the separator to split the string and display it as an array, and only contains two elements var arr = s3.split ('|', 3); // three elements for (var I = 0; I

I hope this article will help you design javascript programs.

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.