Reading a Portion of a String : String : Language Basics JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Language Basics » String »

 

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=VALIGN=middle>
(&nbsp;<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>&nbsp;</TD>
</TR>
</FORM>
</TABLE>
</BODY>
</HTML>


           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Language Basics
» String