0

I have a string string = 'some.value:so this-can be:any.thing, even some.value: too'

I want to strip out the 'some.value:' on the left side.

My failed attempts:

>>> string.lstrip('some.value:')
' this-can be:any.thing, even some.value: too'
>>> string.replace('some.value:','')
'so this-can be:any.thing, even  too'
>>> string.split(':')[1]
'so this-can be'

Expected output: so this-can be:any.thing, even some.value: too

I think the closest to my answer is using the lstrip(). How can I tell the lstrip() to strip exactly the whole phrase?

[!] NOT using any library is preferred!

Note: There is a similar question but the answer is not applicable to me.

Programer Beginner
  • 1,377
  • 6
  • 21
  • 47

1 Answers1

5

We check if the string to strip is a the start, and cut the string if it is the case:

def strip_from_start(strip, string):
    if string.startswith(strip):
        string = string[len(strip):]
    return string

print(strip_from_start('value:', 'value: xxx value: zzz'))
# xxx value: zzz
Thierry Lathuille
  • 23,663
  • 10
  • 44
  • 50