String Manipulation
Bengt Richter
bokr at oz.net
Wed Jul 16 11:35:31 EDT 2003
On 15 Jul 2003 13:23:09 -0700, lamar_air at hotmail.com (lamar_air) wrote:
>I need a piece of code that takes a string like this string1 =
>"aaa/bbb/ccc/dd" and extracts a string containting the character after
>the last "/"
>
>So for this example the result would be "dd"
>
>like this:
>for i=0; string1.right(i) != '/'; i++
>
>result = string1.mid(i, string1.length())
>
>but in python.
Others have posted the split() solutions.
You could also search backward in Python:
>>> s = "aaa/bbb/ccc/dd"
>>> s[s.rfind('/')+1:]
'dd'
>>> s='no_slashes'
>>> s[s.rfind('/')+1:]
'no_slashes'
Regards,
Bengt Richter
More information about the Python-list
mailing list