Reputation: 3479
I have for example these lines:
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
How can I get the part of each line behind <text:
string?
Upvotes: 1
Views: 1004
Reputation: 1802
Try this:
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()));
Francesco
Upvotes: 1
Reputation: 12843
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);
}
Output:
text which i need to store
Upvotes: 1
Reputation: 147
@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);
Upvotes: 1
Reputation: 10553
String result = new String(str.substring(0,str.indexOf("<text:")));
Upvotes: 1
Reputation: 726809
Like this:
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
}
Here is a demo on ideone.
Upvotes: 4