たとえば、次の行があります。
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
}
これは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
@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 result = new String(str.substring(0,str.indexOf("<text:")));
これを試して:
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()));
フランチェスコ