I am trying to split a string twice
String example = response;
String [] array = example.split(\"\");
System.out.println(array[0]);
S
I really don't think you want use split here. I think you want to use something like
// Extract a given tag value from an input txt.
public static String extractTagValue(String txt,
String tag) {
if (tag == null || txt == null) {
return "";
}
String lcText = txt.toLowerCase();
tag = tag.trim().toLowerCase();
String openTag = "<" + tag + ">";
String closeTag = "" + tag + ">";
int pos1 = lcText.indexOf(openTag);
if (pos1 > -1) {
pos1 += openTag.length();
int pos2 = lcText.indexOf(closeTag, pos1 + 1);
if (pos2 > -1) {
return txt.substring(pos1, pos2);
}
}
return "";
}
public static void main(String[] args) {
String example = "Hello World ";
String section = extractTagValue(example,
"section");
String title = extractTagValue(example, "title");
System.out.printf("%s, %s\n", title, section);
}
Which, when executed, outputs
Hello, World