0

how can be done in java, to check string to prompt error when

  • string have special characters which have an EBCDIC value greater than hexadecimal “3F” or
  • an ASCII value greater than hexadecimal “1F”. Occurrences of values EBCDIC “00” - “3F” and ASCII “00” - “1F” are not valid.

sorry if my question repeated or confuse

Thanks in advance

venergiac
  • 7,469
  • 2
  • 48
  • 70
Apache
  • 1,796
  • 9
  • 50
  • 72

1 Answers1

0

You can sort the String as is explained in this answer: Sort a single String in 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.

    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.

Community
  • 1
  • 1
Raul Guiu
  • 2,374
  • 22
  • 37