If I have a long string, say:
"blah blah blah blah blah .............. <ns:return>72.5</ns:return>......abcdejijalskjd;a;l&*^@#()&...."
and I want to extract the value in between the tag, how can I do that?
If I have a long string, say:
"blah blah blah blah blah .............. <ns:return>72.5</ns:return>......abcdejijalskjd;a;l&*^@#()&...."
and I want to extract the value in between the tag, how can I do that?
Do something like:
String str = "blah .... <ns:return>72.5</ns:return>";
String searchBegin = "<ns:return>";
String searchEnd = "</ns:return>";
String subStr = str.substring(str.indexOf(searchBegin) + searchBegin.length(), str.indexOf(searchEnd));
You can use regular expressions, something like:
Pattern p = Pattern.compile(".*<ns:return>(.*)</ns:return>.*");
Matcher m = p.matcher(yourString);
float yourValue = Float.parseFloat(m.group(1));
Use Commons Lang StringUtils
String between = substringBetween(longString, "<ns:return>", "</ns:return>");