Convert string to ASCII - Android java.lang

Android examples for java.lang:Character

Description

Convert string to ASCII

Demo Code

import java.io.UnsupportedEncodingException;

public class Main{

    public static byte[] toASCII(String str) {
        try {/*from  ww  w .  j ava  2 s .c o  m*/
            return str.getBytes("US-ASCII");
        } catch (UnsupportedEncodingException e) {
            /* Should never happen. */
            throw new RuntimeException(e);
        }
    }

}

Related Tutorials