Hi in my program a string is generated like "1&area_id=54&cid=3".First an integer and then a string "&area_id=",then antoher integer, and after that a string "&cid=" and then the final integer.These two strings are always same.But integer is changing.How to write split function so that i can find these three integers in three variable or with in an array.I can seperate these by looping but i want to use split function.Thanks
How about
string.split("&\\w+=")
This works with your example:
System.out.println(Arrays.asList("1&area_id=54&cid=3".split("&\\w+=")));
outputs
[1, 54, 3]
The call to string.split("&\\w+=") reads in English: Split string on every match for the regular expression parameter, and then return all substrings in between the matched tokens as an array.
The regular expression reads: Match all substrings starting with "&", followed by at least ("+") one word-character ("\\w", i.e. letters, digits, and some special characters, such as the underscore from your example), followed by "=". For more details see the Javadoc for java.util.regex.Pattern
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With