Java ASCII from toASCIIString(byte[] data)

Here you can find the source of toASCIIString(byte[] data)

Description

Produces a string using each byte as an ASCII character

License

Open Source License

Parameter

Parameter Description
data a parameter

Declaration

public static String toASCIIString(byte[] data) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from ww  w  .j  ava 2  s.  c o  m
     * Produces a string using each byte as an ASCII character
     * @param data
     * @return
     */
    public static String toASCIIString(byte[] data) {
        if (data == null) {
            return null;
        }

        // TODO: write more efficient implementation
        String s = "";
        for (int i = 0; i < data.length; i++) {
            char b = (char) data[i];
            //            if ( (b >= 0) && (b < 16) )
            //            {
            //                s = s + "0";
            //            }
            s = s + b;
        }
        return s;
    }
}

Related

  1. toAsciiFilename(String string)
  2. toAsciiLowerCase(char ch)
  3. toAsciiString(byte[] buffer)
  4. toAsciiString(byte[] buffer, int startPos, int length)
  5. toAsciiString(byte[] bytes)
  6. toAsciiString(byte[] output)
  7. toAsciiString(String s)
  8. toAsciiString(String value)
  9. toASCIIUpperCase(byte b)