Java ASCII from toAsciiString(String value)

Here you can find the source of toAsciiString(String value)

Description

to Ascii String

License

Open Source License

Declaration

public static String toAsciiString(String value) 

Method Source Code

//package com.java2s;

public class Main {

    public static String toAsciiString(String value) {
        int i, j;
        int len = value.length();

        if ((len % 2) != 0) {
            return value;
        }//from   ww  w . j a v  a 2  s .c  om

        try {
            byte[] byteValue = new byte[len / 2];
            j = 0;
            for (i = 0; i < byteValue.length; i++) {
                byteValue[i] = Byte
                        .parseByte(value.substring(j, j + 2), 16);
                j += 2;
            }

            return new String(byteValue, "US-ASCII");
        } catch (Exception e) {
            return value;
        }
    }
}

Related

  1. toAsciiString(byte[] buffer, int startPos, int length)
  2. toAsciiString(byte[] bytes)
  3. toASCIIString(byte[] data)
  4. toAsciiString(byte[] output)
  5. toAsciiString(String s)
  6. toASCIIUpperCase(byte b)
  7. toASCIIUpperCase(String s)