String manipulation

I have a url that I want to strip a known portion from. Is there a way to do this?



Example:



url=’/watch/showname’



I only want showname.

there’s several different ways to do it. assuming you dont want to mess with regex, see python’s string method docs : http://docs.python.org/library/stdtypes.html#string-methods , one option is str.replace("/watch/","") another is str.strip("/watch/") , or you could try something like str.split(’/’)[1] or a more complex str.format

One more method - if the start of the string is always ‘/watch/’, you can use a slice to just grab to portion of the string you want:



<br />
stringA = '/watch/showname'<br />
stringB = stringA[7:]<br />


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.