6. 30. 1. String.substr() |
|
Syntax |
string.substr(num1, num2)
string.substr(num)
|
|
The substr() method returns the characters starting with the indexed position num1 and counting to num2 characters. |
The string's first character is in position 0. |
If num1 is a negative number, the string starts from the end of the string to begin the substring extraction. |
It is also possible to pass a single index location to the method. |
<html>
<script language="JavaScript1.1">
<!--
var myString = new String("This is a test");
var mySubString = myString.substr(0,6);
document.write('The first 6 characters of our string, ' + myString);
document.write(', are: ' + mySubString);
document.close();
-->
</script>
</html>
|
|