Convert to and from ASCII - Android java.lang

Android examples for java.lang:Character

Description

Convert to and from ASCII

Demo Code

import java.io.UnsupportedEncodingException;

public class Main{

    public static String fromASCII(byte[] bytes) {
        try {//from www  . ja v a  2 s .c  o m
            return new String(bytes, "US-ASCII");
        } catch (UnsupportedEncodingException e) {
            /* Should never happen. */
            throw new RuntimeException(e);
        }
    }
    public static String fromASCII(byte[] bytes, int offset, int len) {
        try {
            return new String(bytes, offset, len, "US-ASCII");
        } catch (UnsupportedEncodingException e) {
            /* Should never happen. */
            throw new RuntimeException(e);
        }
    }

}

Related Tutorials