Reputation: 495
I have an alphanumaric string i want to get only the numbers from that alphanumaric string. Like i have a
string S = Call forwarding [112234]& Multiparty [434566] & Caller line identification[12345]&.
I want to get the string as
string S = 112234 & 434566 &12345 &
so that I can split this string with "&" and pupulate a listview using arrayadapter. currently I am using this method and it shows aphanumaric string like S in first case I want to be it in secound case. Here is my code.
String[] list={};
String ServerResponse = response.toString();
Log.d("Curretnts", "Server response"+ServerResponse);
list =ServerResponse.split("&");
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1, list);
listView1.setAdapter(adapter);
Upvotes: 0
Views: 687
Reputation: 22740
You can extract numbers from string using regex.
Pattern p = Pattern.compile("\\d+");
Matcher m = p.matcher("Call forwarding [112234]& Multiparty [434566] & Caller line identification[12345]&.");
while (m.find())
System.out.println(m.group());
In your example you need to add found items to String[] list={};
.
Upvotes: 3