比如
F:\spket\2131\123.txt
我要截取
spket\2131\
应该如何做
急啊
[code="java"]
String str = "F:\spket\2131\123.txt";
int firstIndex = str.indexOf("\");
int lastIndex = str.lastIndexOf("\");
if(firstIndex != -1 && lastIndex != -1)
str = str.substring(firstIndex + 1, lastIndex + 1);
else if(firstIndex != -1 && lastIndex == -1)
str = str.substring(firstIndex + 1);
else if(firstIndex == -1 && lastIndex != -1)
str = str.substring(0, lastIndex + 1);
System.out.println(str);
[/code]