[英]java string to filter based on particular ascii value
how can be done in java, to check string to prompt error when 如何在Java中完成检查字符串以提示错误
3F
” or 3F
”的特殊字符,或者 1F
”. 1F
”的ASCII值。 Occurrences of values EBCDIC “ 00
” - “ 3F
” and ASCII “ 00
” - “ 1F
” are not valid. 00
”-“ 3F
”和ASCII“ 00
”-“ 1F
”无效。 sorry if my question repeated or confuse 抱歉,如果我的问题重复出现或感到困惑
Thanks in advance 提前致谢
You can sort the String as is explained in this answer: Sort a single String in Java 您可以按照此答案中的说明对字符串进行排序: 在Java中对单个字符串进行排序
char[] chars = original.toCharArray();
Arrays.sort(chars);
Once is sorted you only have to check that the last one in the array of chars is higher than your given hex value. 排序后,只需检查字符数组中的最后一个字符是否高于给定的十六进制值。
For EBCDIC you can add a comparator to the sort and order based on the EBCDIC instead. 对于EBCDIC,您可以改为根据EBCDIC将比较器添加到排序和顺序。
char[] chars = original.toCharArray();
// I will convert my array of chars to array of Characters to use Arrays.sort
int length = Array.getLength(chars);
Character[] ret = new Character[length];
for(int i = 0; i < length; i++)
ret[i] = (Character)Array.get(chars, i);
// and now the important bit
Arrays.sort(ret, new Comparator<Character>() {
@Override
public int compare(Character arg0, Character arg1) {
// convert arg0 and arg1 to EBCDIC with whatever tools you have
return arg0InEBCDIC - arg1InEDBCIC;
}
});
Once you have an ordered array you just need to check the last element as I said. 一旦有了一个有序的数组,您只需检查一下我所说的最后一个元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.