Examples of common methods for string in JavaScript analysis _javascript techniques

Source: Internet
Author: User

The examples in this article describe the common methods of string in JavaScript. Share to everyone for your reference. as follows:

/Length property: Gets the number of characters in the string.
  var s= ' Love Like a gust of wind ';
alert (s.length);
  CharAt (Index) method: Gets the character at the specified index position, starting at 0 var s1= ' I don't want to think of you '; Alert (S1.charat (4));//IndexOf (' e ', StartIndex) method: Gets the location where the specified string appears for the first time.
  startindex indicates that the search starts at the first few.
  var s2= ' After knowing after another autumn ';
Alert (S2.indexof (' over ', 3));//6//Split (' delimiter ', limit); Returns a string to an array based on the delimiter.
  Limit represents the maximum length (customizable) of the array to be returned.
  var s3= ' Gallop | In the rivers and lakes |
Alert (s3.split (' | ', 2));
  Split the string, display the array, and contain only 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 (including), and intercepts Len characters.
  var s4= ' a black sweater '; Alert (S4.SUBSTR (4,2));//sweater, starting with subscript 4 including 4, intercept two characters//substring (startindex,stopindex) starting from StartIndex,//
  Intercept to Stopindex position (excluding Stopindex characters) var s5= ' fireworks easy to cool personnel ';
  Alert (s5.substring (1,4));//flowers easy to cool, starting from 1 to 4, excluding 1 and 4//toUpperCase () Convert uppercase, toLowerCase (), convert lowercase var s6= ' What Are you kidding me ';
  Alert (S6.touppercase ());

Alert (S6.tolowercase ()); 

The

wants this article to help you with your JavaScript programming.

Related Article

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.