清理字符串中的数字Java实现

package test;

//清理字符串中的数字
public class cleanint {

	//思路是用charat逐字符读取,对数字进行判读,发现有字符的用空格替代,最后删除空格
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String str ="23f2br4bb43h53h53h2v";
		for (int i = 0; i < str.length(); i++) {
			if (Character.getNumericValue(str.charAt(i))>0&&Character.getNumericValue(str.charAt(i))<9) {
				str=str.replace(str.charAt(i), ' ');    //上面要用char的包装类才能转换,左边注意用法
			}
			str=str.replaceAll(" ", "");                //删除空格
		}
		System.out.println(str);
	}
}

猜你喜欢

转载自blog.csdn.net/m15682532244/article/details/78371234