.substr()
The .substr()
method returns a portion of a string specified by a starting position and length.
Syntax
baseString.substr(pos,len)
baseString
is the string whose substring is being returned.pos
is the zero-based starting position of the substring. An exception is thrown ifpos
is greater than.size()
.len
is the number of characters to return in the substring. Iflen
is greater than the number of characters afterpos
, the whole remainder of the string is returned.
Codebyte Example
The following example prints out a section of a longer string.