Return a copy of a substring of a string.
First parameter is the starting position and second parameter is the number of characters to copy.
But if the second parameter is greater than the remaining characters in the string, it isn't an error. It just means copy all the remaining characters.
- s.substr(0,4) // return a copy of 4 characters begining at position 0 of s
- s.substr(3) // return a copy of all the characters in s starting at position 3
- s.substr(3, string::npos) // return a copy of all the characters in s starting at position 3
The starting position must be a valid position in the string; that is, the start position, p, must satisfy:
0 <= p < s.length()
The length parameter can be larger than the number of characters remaining from the starting position.