Trim Whitespace from Strings
Learn to trim whitespace from strings.
We'll cover the following
It is common for input from users to include string
class methods, find_first_not_of()
and find_last_not_of()
, to trim whitespace from the ends of a string.
How to do it
The string
class includes methods for finding elements that are, or are not, included in a list of characters. We'll use these methods to trim string
:
We start by defining
string
with input from a hypothetical ten-thumbed user:
Get hands-on with 1400+ tech skills courses.