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.