2011-08-30 167 views

回答

5

測試並將取代任意數量的斜線。

String path = yourString.replaceFirst("file:/*", ""); 

如果你只希望它匹配兩個或三個斜槓

String path = yourString.replaceFirst("file:/{2,3}", ""); 
+0

非常感謝 –

+0

第二種解決方案。 :) – user802421

+0

'[]'是多餘的。另外,'///?'比'/ {2,3}'更簡短。 –

0

可以替換字符串 「文件://」 在字符串中什麼也沒有:

String path = yourString.replace("file://", ""); 
+0

如果它所包含的3個斜線像'文件:///'? –

+0

上面的答案不會滿足file:/// f:/ temp/.... file:/// H:/ something/.... – developer

+0

'String path = yourString.replaceFirst(「^ file:// /?「,」「);' - 沒有方法'String.replace(String,String)'。 –

0

什麼步驟呢?

String path = yourString.replaceFirst("file:[/]*", ""); 
+0

'[]'是多餘的。 –

1
String path = new java.net.URI(fileUrl).getPath();