2010-10-18 46 views

回答

4

沒有正則表達式的需要:

path = path.substring(0, path.lastIndexOf('/') + 1); 

參考:lastIndexOf()substring()

您可能要事先檢查,該字符串是否包含斜槓:

var index = path.lastIndexOf('/'); 
if(index > -1) { 
    path = path.substring(0, index + 1); 
} 
+0

字符串將始終包含一個斜槓,因爲這是我在插件中編寫的代碼。但從來沒有更少,一個很好的控制:) – Steven 2010-10-18 14:29:49

+0

費利克斯 - 從技術上講,你會想要'''path.lastIndexOf('/')''爲了得到結果要求的問題。 :o) – user113716 2010-10-18 14:31:18

+0

@patrick dw:Ups,你是對的......謝謝! – 2010-10-18 14:37:30