I have a text string that starts with a number of spaces, varying between 2 & 4.
What is the simplest way to remove the leading whitespace? (ie. remove everything before a certain character?)
" Example" -> "Example"
" Example " -> "Example "
" Example" -> "Example"
Best Answer
The
lstrip()
method will remove leading whitespaces, newline and tab characters on a string beginning:Edit
As balpha pointed out in the comments, in order to remove only spaces from the beginning of the string,
lstrip(' ')
should be used:Related question: