1. Are you ready for the Galaxy S20? Here is everything we know so far!

How to convert extended ASCII character to number in Android?

Discussion in 'Android Development' started by adamhala007, Aug 10, 2013.

  1. adamhala007

    adamhala007 Lurker
    Thread Starter


    Can you help me, please? I'm working on an Android app. I get some characters from a file on the Internet and put it to a TextView. These characters are ASCII characters. Then I read these characters one by one and convert it to numbers with the following code:

    final String textSource = "path to my file";
    URL textUrl;
    try {
    textUrl = new URL(textSource);
    BufferedReader bufferReader = new BufferedReader(
    new InputStreamReader(textUrl.openStream()));
    String StringBuffer;
    String stringText = "";
    while ((StringBuffer = bufferReader.readLine()) != null) { stringText += StringBuffer;
    String PT = textMsg.getText().toString();
    CharSequence c = new String(PT);
    char my_char2;
    char my_char3;
    int myNum = 0;
    for (int k = 170; k < len; k++) {
    if (c.charAt(k) == '0' && c.charAt(k+1) == '.') {
    my_char2 = c.charAt(k+13);
    my_char3 = c.charAt(k+14);
    myNum = my_char2 * 256 + my_char3;

    Then I write it to an another TextView:

    crlNumber.setText("" + myNum);

    The problem is that this can only convert standard ASCII characters(from 0 to 127) except of the new line character(character number 10), carriage return character(character number 13) and the cancel character(character number 24).
    But I need to convert also the extended ASCII characters(from 128 to 255) and the 3 characters mentioned above.
    What should I do?
    Thanks for helping.


Share This Page