例如,我有以下几行:
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
}
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
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()));
弗朗切斯科