.substr() method returns a portion of a string specified by a starting position and length.
baseStringis the string whose substring is being returned.
posis the zero-based starting position of the substring. An exception is thrown if
posis greater than
lenis the number of characters to return in the substring. If
lenis greater than the number of characters after
pos, the whole remainder of the string is returned.
The following example prints out a section of a longer string.
Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.
Learn C++ on Codecademy
Computer ScienceLooking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
Includes 6 Courses
With Professional Certification