我有这些行:
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:
字符串后面?
答案 0 :(得分:4)
像这样:
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
}
答案 1 :(得分:1)
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
答案 2 :(得分:1)
String result = new String(str.substring(0,str.indexOf("<text:")));
答案 3 :(得分:1)
@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);
答案 4 :(得分:1)
试试这个:
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()));
弗朗西斯