I have Strings in this format :
file://c:/Users/....
file://E:/Windows/....
file:///f:/temp/....
file:///H:/somethi开发者_如何转开发ng/....
How can I get just c:/Users/...
or H:/something/...
?
Tested and will replace an arbitrary number of slashes.
String path = yourString.replaceFirst("file:/*", "");
And if you only want it to match two or three slashes
String path = yourString.replaceFirst("file:/{2,3}", "");
String path = new java.net.URI(fileUrl).getPath();
you can replace the string "file://" in your string with nothing:
String path = yourString.replace("file://", "");
What about that?
String path = yourString.replaceFirst("file:[/]*", "");
精彩评论