1

例如,我有以下几行:

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:我怎样才能得到字符串后面每行的部分?

4

5 回答 5

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
}

这是关于 ideone 的演示

于 2013-04-08T13:18:41.060 回答
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
于 2013-04-08T13:18:15.073 回答
1
String result = new String(str.substring(0,str.indexOf("<text:")));
于 2013-04-08T13:20:01.043 回答
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);
于 2013-04-08T13:24:12.153 回答
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()));

弗朗切斯科

于 2013-04-08T13:30:02.017 回答