I have a string like this:
["477","com.dummybilling","android.test.purchased","inapp:com.dummybilling:android.test.purchased","779"]
How to have a String[] with these 5 element?
Does anyone know a regex for .split()
method?
Thank you very much, regular expressions make me crazy! :(
A character array is a sequence of characters, just as a numeric array is a sequence of numbers. A typical use is to store a short piece of text as a row of characters in a character vector.
String class split(String regex) can be used to convert String to array in java. If you are working with java regular expression, you can also use Pattern class split(String regex) method.
Process it as JSON. Two immediate benifits would be that it would take care of any embedded commas in your data automatically and the other that you would get a String[]
with unquoted strings.
String input = "[\"477\",\"com.dummybilling\",\"android.test.purchased\",\"inapp:com.dummybilling:android.test.purchased\",\"779\"]";
JSONArray jsonArray = new JSONArray(input);
String[] strArr = new String[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
strArr[i] = jsonArray.getString(i);
}
System.out.println(Arrays.toString(strArr));
Output :
[477, com.dummybilling, android.test.purchased, inapp:com.dummybilling:android.test.purchased, 779]
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