Java ASCII from toAsciiArray(char[] carr)

Here you can find the source of toAsciiArray(char[] carr)

Description

Converts char array into ASCII array.

License

Open Source License

Declaration

public static byte[] toAsciiArray(char[] carr) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from   w  w w .  j  a va  2 s  .  c  om
     * Converts char array into ASCII array.
     * @see #toAscii(char)
     */
    public static byte[] toAsciiArray(char[] carr) {
        if (carr == null)
            return null;
        byte[] barr = new byte[carr.length];
        for (int i = 0; i < carr.length; i++)
            barr[i] = (byte) toAscii(carr[i]);
        return barr;
    }

    /**
     * Converts char sequence into ASCII array.
     */
    public static byte[] toAsciiArray(CharSequence charSequence) {
        if (charSequence == null)
            return null;
        byte[] barr = new byte[charSequence.length()];
        for (int i = 0; i < barr.length; i++)
            barr[i] = (byte) toAscii(charSequence.charAt(i));
        return barr;
    }

    /**
     * Returns ASCII symbol of a char. In case of overload, 0x3F is returned.
     */
    public static int toAscii(char c) {
        if (c <= 0xFF)
            return c;
        else
            return 0x3F;
    }
}

Related

  1. toAscii(String s)
  2. toAscii(String s)
  3. toASCII(String s)
  4. toAscii(String s)
  5. toASCII(String str)
  6. toAsciiByteArray(final char[] carr)
  7. toAsciiByteArray(String s)
  8. toAsciiBytes(final String value)
  9. toAsciiBytes(String str)