I need to convert a string stored like,
textView.setText(myVar);
Here myVar = "23,45,64,78";
I would like it to convert into array like below,
int[] xAxis = new int[]{23,45,64,78};
How can I achieve this? Thanks
I need to convert a string stored like,
textView.setText(myVar);
Here myVar = "23,45,64,78";
I would like it to convert into array like below,
int[] xAxis = new int[]{23,45,64,78};
How can I achieve this? Thanks
Try this:
String arr = "[23,45,64,78]";
String[] items = arr.replaceAll("\\[", "").replaceAll("\\]", "").split(",");
int[] results = new int[items.length];
for (int i = 0; i < items.length; i++) {
try {
results[i] = Integer.parseInt(items[i]);
} catch (NumberFormatException nfe) {};
}