我有我的Python應用程序的字符串看起來是這樣的:減少在Python中的特定點
test1/test2/foo/
每次我得到這樣一個字符串,我想減少它,從尾部開始,減少直至拳頭「/」已達到。
test1/test2/
更多的例子:
foo/foo/foo/foo/foo/ => foo/foo/foo/foo/
test/test/ => test/
how/to/implement/this => how/to/implement/
我怎樣才能在Python實現這一點?
在此先感謝!
或者,您可以使用'.rfind('/',0,-2)'。 – kennytm 2010-01-27 08:33:15
太棒了!非常感謝!!! – Neverland 2010-01-27 11:13:10
這確實是最差的答案之一。 – SilentGhost 2010-01-27 14:05:40