Common Methods of String in Javascript: instance analysis and string instance analysis

Source: Internet
Author: User

Common Methods of String in Javascript: instance analysis and string instance analysis

This article describes the common methods of String in Javascript. 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 <arr. length; I ++) {alert (arr [I]) ;}// substr (startIndex, len) starts from startIndex (inclusive), and then intercepts len characters. Var s4 = 'one-piece Black url'; alert (s4.substr (); // sweater, which starts from subscript 4 and contains 4. capture two characters later. // substring (startIndex, stopIndex) starting from startIndex, // capture to the stopIndex position (excluding the character of stopIndex) var s5 = 'fireworks easy-to-use easy-to-split '; alert (s5.substring )); // easy to use, starting from 1 to 4, excluding 1 and 4 // toUpperCase () converts uppercase and toLowerCase (); convert lowercase var s6 = 'what are you kidding me'; alert (s6.toUpperCase (); alert (s6.toLowerCase ());

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.