• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Want to convert string ?

coder05

Lurker
Hi,
I am new to android and want to convert this string
textView.setText(myVar);

Here
[HIGH]
myVar = 12,15,47,22;
[/HIGH]
I need to convert the above string to the following string,
[HIGH]
int[] xAxis = new int[{12,15,47,22}];
[/HIGH]
Please help, thanks.
 
I figured out so I wanted to post the code. Hope it helps someone.


[HIGH] String myStr = "[1,2,3,4,5]";
String see = myStr.trim();

String[] items = see.replaceAll("\\[", "").replaceAll("\\]", "").split(",");


int[] results = new int[items.length];
for (int i = 0; i < items.length; i++) {
try {
results = Integer.parseInt(items);


} catch (NumberFormatException nfe) {};
}



[/HIGH]
 
Back
Top Bottom