我有例如,這些線路的背後:字符串 - 得到的字符串中指定的子
af asf af dassfdfsdf a dfa sd<text:text which i need to store
xycCYXCYXCaAdadad<text:text which i need to store
56afdasfaaaaaa54554 ewrt<text:text which i need to store
我怎麼能落後<text:
串的每一行的一部分嗎?
我有例如,這些線路的背後:字符串 - 得到的字符串中指定的子
af asf af dassfdfsdf a dfa sd<text:text which i need to store
xycCYXCYXCaAdadad<text:text which i need to store
56afdasfaaaaaa54554 ewrt<text:text which i need to store
我怎麼能落後<text:
串的每一行的一部分嗎?
像這樣:
String line = "af asf af dassfdfsdf a dfa sd<text:text which i need to store";
int pos = line.indexOf("<text:");
if (pos > 0) {
line = line.substring(pos+6); // 6 is the length of your "<text:" marker
}
這裏是一個demo on ideone。
public static void main(String[] args) {
String str = "af asf af dassfdfsdf a dfa sd<text:text which i need to store";
String result = str.substring(str.indexOf("<text:")+"<text:".length());
System.out.println(result);
}
輸出:
text which i need to store
@dasblinkenlight謝謝。 – 2013-04-08 13:23:26
String result = new String(str.substring(0,str.indexOf("<text:")));
@gaffcz,....
Try below code once
String str = "af asf af dassfdfsdf a dfa sd<text:text";
int lastIndex = str.lastIndexOf("<text:text");
str = str.substring(0, lastIndex);
System.out.println("str : "+str);
試試這個:
String a ="af asf af dassfdfsdf a dfa sd<text:text"; System.out.println(a.subSequence(0, a.lastIndexOf("<text:text") != -1 ? a.lastIndexOf("<text:text"): a.length()));
弗朗西斯
謝謝解答! :-) – gaffcz 2013-04-08 13:32:12
你應該使用正則表達式來減少你想要的分隔符,比如在這種情況下:''
2013-04-08 13:18:40