Reputation: 1
- I have one query. There are three strings .I
your text` want to separate locator and value .
String s1 = "id=txtussername"; String s2 = "CSSselector=#txtusername"; String s3 = "xpath=//tagnme\[@att='cytrix'\]"; String[] words = s1.split("="); for (String word : words) { System.out.println(word); }
but for string s3 the above code is not applicable. i want to write common code for all three strings to separate locators and value`
Upvotes: 0
Views: 60
Reputation: 2282
Use indexOf("=")
to find the position of the first occurrence of "=". Then you can simply use substring()
with the corresponding indices to get locator and value.
String s = "string=multiple=equals";
int sep_Pos = s.indexOf("=");
String locator = s.substring(0, sep_Pos);
String value = s.substring(sep_Pos+1);
Upvotes: 1