public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String str = "方圆100公里";
getNumber(str);
}
public String getNumber(String str){
Pattern pattern = Pattern.compile("[0-9]*");
StringBuffer temp = new StringBuffer();
Matcher isNum;
char[] array = str.toCharArray();
for (int i = 0; i < array.length; i++) {
Log.e("value :" + i,"=----"+ array[i]);
isNum = pattern.matcher(array[i]+"");
if(isNum.matches()){
temp.append(array[i]);
}else{
continue;
}
}
Log.e("temp value ", temp.toString());
return temp.toString();
}
}