Reputation: 127
i have have a string looks :
mystring = "<EQHO state="degraded"...> at /NE[1]/EQHO[2]/@state to <EQHO state="working"...> at /NE[1]/EQHO[1]/@state"
and i want to get this value :
value="NE[1]/EQHO[1]"
how can i achieve that ? thanks
Upvotes: 0
Views: 85
Reputation: 22474
Try this:
mystring.substring(mystring.lastIndexOf("at /")+4, mystring.lastIndexOf("/@"))
but you probably should use a more generic solution. To extract all the section that have this format you can use something like this:
String mystring = "<EQHO state=\"degraded\"...> at /NE[1]/EQHO[2]/@state to <EQHO state=\"working\"...> at /NE[1]/EQHO[1]/@state";
ArrayList<String> values = new ArrayList<String>();
while(mystring.indexOf("at /") < mystring.indexOf("/@")){
String val = mystring.substring(mystring.indexOf("at /") + 4, mystring.indexOf("/@"));
values.add(val);
mystring = mystring.substring(mystring.indexOf("/@")+2);
}
System.out.println(values);
Upvotes: 1
Reputation: 51
You can change the value of a string like this
mystring = "NE[1]/EQHO[1]";
Remember to include the semicolon!
Upvotes: 0