.substr()
Published Jun 2, 2022Updated Dec 21, 2022
Contribute to Docs
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.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.