String Manipulation

Cousin Stanley CousinStanley at hotmail.com
Tue Jul 15 22:58:09 CEST 2003


| 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"
| ...

lamar_air ...

Here is one way ...


>>> str_in = 'aaa/bbb/ccc/dd'
>>>
>>> list_in = str_in.split( '/' )
>>>
>>> last_element = list_in[ -1 ]
>>>
>>> print last_element
dd
>>>


-- 
Cousin Stanley
Human Being
Phoenix, Arizona






More information about the Python-list mailing list