JavaScript: string functions: substr() vs substring()
The tutor describes the difference between substr() and substring()
Let’s imagine the string variable
var strng_ex=”this_example_string”;
The function substr(4,5) returns 5 characters from the string, starting at the fourth position (which is _, since the first position is 0):
strng_ex.substr(4,5) has value _exam
The function substring(4,5) returns a sequence of characters from the string, starting at position 4, then ending before position 5. Therefore, the value of
strng_ex.substring(4,5) is just _
HTH:)
Source:
Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.
Leave a Reply
You must be logged in to post a comment.