Reading a Portion of a String
<HTML>
<HEAD>
<TITLE>String Slicing and Dicing, Part II</TITLE>
<SCRIPT LANGUAGE="JavaScript">
var mainString = "This is a test"
function showResults() {
var form = document.forms[0]
var param1 = parseInt(form.param1.options[form.param1.selectedIndex].value)
var param2 = parseInt(form.param2.options[form.param2.selectedIndex].value)
if (!param2) {
alert(mainString.substr(param1));
} else {
alert(mainString.substr(param1, param2));
}
}
</SCRIPT>
</HEAD>
<BODY onLoad="showResults()">
<B>String substr() Method</B>Text used for the methods:<B>This is a test<BR>
<TABLE>
<FORM>
<TR><TH>String Method</TH><TH>Method Parameters</TH></TR>
<TR>
<TD>string.substr()</TD><TD ROWSPAN=3 VALIGN=middle>
( <SELECT NAME="param1" onChange="showResults()">
<OPTION VALUE=0>0
<OPTION VALUE=1>1
<OPTION VALUE=2>2
<OPTION VALUE=3>3
<OPTION VALUE=5>5
</SELECT>,
<SELECT NAME="param2" onChange="showResults()">
<OPTION >(None)
<OPTION VALUE=5>5
<OPTION VALUE=10>10
<OPTION VALUE=20>20
</SELECT> ) </TD>
</TR>
</FORM>
</TABLE>
</BODY>
</HTML>
Related examples in the same category