String Manipulation

Vinoo Vasudevan ee01b092 at ee.iitm.ernet.in
Tue Jul 15 22:51:56 EDT 2003


lamar_air at hotmail.com (lamar_air) wrote in message news:<2c6431ab.0307151223.4173c4ee at posting.google.com>...
> 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.

How about this: 
string1 = 'aaa/bbb/ccc/dd'
result = string1[string1.rfind('/')+1:]

Hope it's helpful,

Vinoo




More information about the Python-list mailing list