Published Jun 2, 2022Updated Dec 21, 2022
Contribute to Docs
.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.
- garanews222 total contributions
- StevenSwiniarski475 total contributions
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
Beginner Friendly82 Lessons