String.substring() : substring : String JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » String » substring »

 

String.substring()














Syntax








string.substring(num1, num2)
    string.substring(num)



The substring() method returns the characters starting with the indexed position num1 and ending with the character before num2.

The string's first character is in position 0.

If you pass num1 as a negative number, it will be treated as 0.

If you pass num2 as a value greater than the string.length property, it will be treated as string.length.

If num1 equals num2, an empty string is returned.

It is also possible to pass a single index location to the method.












<html>
    <script language="JavaScript">
    <!--
    var myString = new String("This is a test");

    var mySubString = myString.substring(0,10);
    document.write('The first 10 characters of our string, ' + myString);
    document.write(', are: ' + mySubString);
    document.close();
    -->
    </script>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo String
» substring