java 中对于字符串中字符型数组-数据分析
字符型数据范围
常用范围:
大写字母(A-Z):65 (A)~ 90(Z)
小写字母(a-z):97(a) ~ 122(z)
字符数字('0' ~ '9'):48('0') ~ 57('9')
通过获取字符串中的字符型数组,进行字符串解析
public static void main(String[] args) {
String str = "Nf2Co2";
char[] olbChars = str.toCharArray();
char[] newChars = new char[olbChars.length];
int i = 0;
for (int num = 0 ; num < olbChars.length; num++) {
newChars[i] = olbChars[num];
// 大写字母
if (isUpperCase(olbChars[num])) {
// 如果是最后一个大写
if (num == olbChars.length - 1) {
String newStr = new String(newChars);
System.out.println("数据库查询:" +newStr);
}
}
// 小写字母
if (isLowerCase(olbChars[num])) {
// 如果是最后一个小写
if (num == olbChars.length - 1) {
String newStr = new String(newChars);
System.out.println("数据库查询:" +newStr);
}else {
int nextChar = olbChars[num + 1];
// 下一个不是数字 ,并且下一个不是小写,那么查询数据库
if (!isNumber(nextChar) && !(isLowerCase(nextChar))) {
i = -1;
String newStr = new String(newChars);
newChars = new char[olbChars.length];
System.out.println("数据库查询:" +newStr);
}
}
}
// 数值
if (isNumber(olbChars[num])) {
newChars[i] = 32;
i = -1;
String newStr = new String(newChars).trim();
newChars = new char[olbChars.length];
System.out.println("数据库查询:" +newStr + ",乘以:" + olbChars[num]);
}
i++;
}
}
/**
* 是否为数字
*
* @param intChars char/ int类型
* @return true
*/
private static boolean isNumber(int intChars) {
return intChars >= 48 && intChars <= 57;
}
/**
* 判断是否小写
*
* @param intChars char/ int类型
* @return true
*/
private static boolean isLowerCase(int intChars) {
return intChars >= 97 && intChars <= 122;
}
/**
* 判断是否大写
*
* @param intChars char/ int类型
* @return true
*/
private static boolean isUpperCase(int intChars) {
return intChars >= 65 && intChars <= 90;
}
解析得到单个的字符