Java Utililty Methods ASCII

List of utility methods to do ASCII

Description

The list of methods to do ASCII are organized into topic(s).

Method

byte[]asciiEbcdic(String source)
Convert the ASCII string to an array of bytes in EBCDIC.
int len;
byte[] pBuf = source.getBytes();
len = source.length();
for (int i = 0; i < len; i++) {
    pBuf[i] = (byte) translateByte((pBuf[i] & 0xFF), "EBCDIC");
return pBuf;
booleanasciiEndsWithIgnoreCase(String source, String suffix)
Returns whether the given source string ends with the suffix, ignoring case and assuming that the strings are ascii encoded.
int length = suffix.length();
if (length > source.length()) {
    return false;
int offset = source.length() - length;
for (int i = 0; i < length; i++) {
    char c1 = source.charAt(i + offset);
    char c2 = suffix.charAt(i);
...
booleanasciiEqualsIgnoreCase(byte[] a, byte[] b)
ascii Equals Ignore Case
if (a.length != b.length) {
    return false;
for (int i = 0; i < a.length; ++i) {
    if (Character.toLowerCase((char) a[i]) != Character.toLowerCase((char) b[i])) {
        return false;
return true;
booleanasciiEqualsIgnoreCase(byte[] buf1, byte[] buf2)
Compares the given byte arrays and returns whether they are equal, ignoring case differences and assuming they are ascii-encoded strings.
if (buf1 == null || buf2 == null) {
    return false;
if (buf1 == buf2) {
    return true;
if (buf1.length != buf2.length) {
    return false;
...
StringasciiFill2(String str, int startIdx, String fillStr)
ascii Fill
int idx = asciiIdx2StrIdx(str, startIdx);
String ret = "";
if (idx == -1) {
    ret = asciiPaddingR(str, startIdx, " ");
    ret += fillStr;
} else {
    ret = str.substring(0, idx) + fillStr;
    if (ret.length() < str.length())
...
Stringasciify(String s)
Converts the characters in the given string to equivalent ascii value.
String temp = "\"";
for (int i = 1; i < s.length() - 1; i++)
    temp += String.format("%2X", (int) s.charAt(i)).replace(' ', '0');
return temp + "\"";
intasciiIdx2StrIdx(String str, int asciiIdx)
ascii Idx Str Idx
int length = 0;
for (int i = 0; i < str.length(); i++) {
    char c = str.charAt(i);
    length += c > 127 ? 2 : 1;
    if (length >= asciiIdx)
        return i;
return -1;
...
intasciiLength(String str)
ascii Length
int length = 0;
for (int i = 0; i < str.length(); i++) {
    char c = str.charAt(i);
    length += c > 127 ? 2 : 1;
return length;
StringasciiPaddingR(String str, int length, String padding)
ascii Padding R
String rst = asciiTrimR(str, length);
int alen = asciiLength(rst);
if (alen == length)
    return rst;
rst += repeat(padding, (length - alen) / asciiLength(padding));
return rst;
int[]asciiQuads(String word)
ascii Quads
int blen = word.length();
int[] result = new int[(blen + 3) / 4];
for (int i = 0; i < blen; ++i) {
    int x = word.charAt(i);
    if (++i < blen) {
        x = (x << 8) | word.charAt(i);
        if (++i < blen) {
            x = (x << 8) | word.charAt(i);
...