<strong>Split</strong> method: <br>The following program example realizes the usage of split and integer string conversion. . . <br><script > <br>function evil() <br>{ <br>var toint=parseInt("123");//Convert string to integer <br>var intvalue=123; <br> var tostr=intvalue.toString();//Type conversion to string<br>var my_friends ="test1,test2,test3,test4,test5"; <br>var friend_array =my_friends.split(","); <br>for (loop=0; loop < friend_array.length;loop ) <BR>{ <BR>document.writeln(friend_array[loop] " is myfriend.<br>"); <br>} <br> } <br><strong>indexOf method: </strong> <br>Returns the character position of the first substring occurrence in the String object. <br>strObj.indexOf(subString[, startIndex]) <br>Parameters <br>strObj <br>Required. String object or literal. <br>subString <br>Required. The substring to find in the String object. <br>starIndex <br>Optional. This integer value indicates the index within the String object at which to begin the search. If omitted, the search is from the beginning of the string. <br>Description <br>The indexOf method returns an integer value indicating the starting position of the substring within the String object. If the substring is not found, -1 is returned. <br>If startindex is negative, startindex is treated as zero. If it is greater than the largest character position index, it is treated as the largest possible index. <br>Perform the search from left to right. Otherwise, the method is the same as lastIndexOf. <br>Example <br>The following example illustrates the use of the indexOf method. <br>Program code<br><div class="codetitle"> <span><a style="CURSOR: pointer" data="25063" class="copybut" id="copybut25063" onclick="doCopy('code25063')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code25063"> <br>function IndexDemo(str2){ <br>var str1 = "BABEBIBOBUBABEBIBOBU" <br>var s = str1.indexOf(str2); <br>return(s); <br>} <br> </div> <br><strong>lastIndexOf method: <br></strong>Returns the last occurrence position of the substring in the String object. <br>strObj.lastIndexOf(substring[, startindex]) <br>Parameters <br>strObj <br>Required. String object or literal. <br>substring <br>Required. The substring to find within the String object. <br>startindex <br>Optional. This integer value indicates the index within the String object at which to start the search. If omitted, the search starts at the end of the string. <br>Description <br>The lastIndexOf method returns an integer value indicating the starting position of the substring within the String object. If the substring is not found, -1 is returned. <br>If startindex is negative, startindex is treated as zero. If it is greater than the largest character position index, it is treated as the largest possible index. <br>Perform the search from right to left. Otherwise, this method is the same as indexOf. <br>The following example illustrates the usage of the lastIndexOf method: <br>Program code<br><div class="codetitle"> <span><a style="CURSOR: pointer" data="16777" class="copybut" id="copybut16777" onclick="doCopy('code16777')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code16777"> <br>function lastIndexDemo(str2) <br>{ <br>var str1 = "BABEBIBOBUBABEBIBOBU" <br>var s = str1.lastIndexOf(str2); <br>return(s); <br>} <br> </div> <br><strong>substring method: <br></strong>Returns the substring located at the specified position in the String object. <br>Program code<br>strVariable.substring(start, end) <br>"String Literal".substring(start, end) <br>Parameter<br>start <br>Indicates the starting position of the substring, The index starts from 0. <br>end <br> specifies the end position of the substring, the index starts from 0. <br>Description <br>The substring method will return a string containing the substring from start to the end (excluding end). The <br>substring method uses the smaller of start and end as the starting point of the substring. For example, strvar.substring(0, 3) and strvar.substring(3, 0) will return the same substring. <br>If start or end is NaN or negative, replace it with 0. <br>The length of the substring is equal to the absolute value of the difference between start and end. For example, in strvar.substring(0, 3) and strvar.substring(3, 0) the length of the substring returned is 3. <br>Example <br>The following example demonstrates the use of the substring method. <br>Program code<br><div class="codetitle"> <span><a style="CURSOR: pointer" data="94751" class="copybut" id="copybut94751" onclick="doCopy('code94751')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code94751"> <br>function SubstringDemo(){ <br>var ss; // Declare variables. <br>var s = "The rain in Spain falls mainly in the plain.."; <br>ss = s.substring(12, 17); // Get the substring. <br>return(ss); // Return substring. <br>}<br> </div>