Reputation: 1318
I was trying to strip a string like
var/vob/bxxxxx/xxxxx/vob
I am doing it like...
'var/vob/bxxxxx/xxxxx/vob'.lstrip('/var/vob/')
I am expecting an output like ...
bxxxxx/xxxx/vob
But it is only giving...
xxxx/xxxxxx/vob
Yes I know because of the first letter is b and in python prefix b for a string stands for converting it into bytes, and I have read this too...
But what I wanted to know is how to bypass this thing.. I want to get the desired output...
I would love to say the things I have tried.. but I don't find any way around to try... can some one throw some light on this...
Thanks :)
Upvotes: 0
Views: 617
Reputation: 239443
The best way to do this would be, like this
data, text = "/var/vob/bxxxxx/IT_test/vob", "/var/vob/"
if data.startswith(text): data = data[len(text):]
print data
Output
bxxxxxx/IT_test/vob
Upvotes: 2
Reputation: 12867
What about
if s.startswith("var/vob/):
s = s[8:]
And yes, Mark is right, lstrip
removes any haracters from contained in the argument from the string.
Upvotes: 2
Reputation: 308091
You misunderstand what lstrip
does. It removes all characters that are part of the parameter string. Order doesn't matter. Since b
is in the string it is removed from the front of the result.
Upvotes: 6