Java ASCII to String asciiBytesToChar(byte[] bytes)

Here you can find the source of asciiBytesToChar(byte[] bytes)

Description

Converts bytes from ascii encoded text to a char[] and zero outs the original byte[]

License

LGPL

Parameter

Parameter Description
bytes the bytes from an ascii encoded text (note - no validation is done to ensure ascii encoding)

Return

the corresponding char[]

Declaration

public static char[] asciiBytesToChar(byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**// w ww  .ja  v a  2s  . c om
     * Converts bytes from ascii encoded text to a char[] and zero outs the original byte[]
     *
     * @param bytes the bytes from an ascii encoded text (note - no validation is done to ensure ascii encoding)
     * @return the corresponding char[]
     */
    public static char[] asciiBytesToChar(byte[] bytes) {
        char[] chars = new char[bytes.length];
        for (int i = 0; i < bytes.length; i++) {
            chars[i] = (char) bytes[i];
            bytes[i] = '\0';
        }
        return chars;
    }
}

Related

  1. ascii2Str(String s)
  2. ascii2String(String ASCIIs)
  3. asciiBytesToString(byte[] val)
  4. ASCIIToChar(final int ascii)
  5. AsciiToChar(int asc)
  6. asciiToLowerCase(String s)