java


Android converting string to array string [closed]


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! :(
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]
You can split your string by separator [" (the beginning) or "," or "] (the ending) like this:
final String[] tokens = yourString.split("\",\"|\\[\"|\"\\]");
Please note that this will only work for your string. It's not a general solution (for example, it does not take care of any escaped quotes). If your string is in JSON format, you should use a JSON parser as proposed by #Ravi Thapliyal .

Related Links

How to handle several events for the same Node in JavaFX using only one Event Handling class?
Spring with HSQLDB latest 2.4.0 version not working
Java Spark Data Encoding
Ignite data afinnity for 2 caches
Set -noverify flag in java code
Testing if an Array is empty JUNIT
Exception Handling in Morphia (Java)
Cannot get shared preferences inside custom context wrapper injection
Is the choice of Scala Akka vs Java Akka just a choice of hooks into the framework?
getting null values when trying to pass values to xml response in web service from model class
android settext only if it starts with
LocalDateFormatter day of month cardinality
Placing an array of buttons in 2 columns
Clojure REPL, interop, Unable to resolve symbol
how to tomcat server.xml include another xml in eclipse?
Let's encrypt certificate issuance fails

Categories

HOME
debugging
image-processing
gremlin
programming-languages
yahoo-oauth
fsm
icloud
sql-server-2016
serverspec
add
slurm
modx-revolution
after-effects
ehcache
claims-based-identity
buildbot
sparse-matrix
fish
semantic-analysis
status
windows-error-reporting
xacml
google-cloud-nl
librato
fog
framemaker
vxworks
turbogears
netcdf4
fault
jquery-nestable
pebble-watch
tizen-native-app
lowpass-filter
statsd
nativeapplication
windows-iot-core-10
qtwebview
akka-cluster
mako
flow-control
linode
arrow-keys
gcsfuse
sqldf
imanage
google-feed-api
heidisql
savon
thrust
gridview-sorting
dlna
thredds
android-listview
operation
composite
graph-api-explorer
codeigniter-routing
onactivityresult
flask-cors
project-planning
rtmfp
mbr
ril
orchardcms-1.7
spring-validator
clipper
factory-method
tinn-r
quickdialog
cascalog
uiviewanimation-curve
postgresql-performance
jquery-ui-layout
pendrive
cufon
cinema-4d
rfc1123
actionview
blitz++
createwindow
gallio
filtered-index
multi-tier
privilege
rtml

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App