How to convert ASCII to int?

前端 未结 8 1330
独厮守ぢ
独厮守ぢ 2021-01-17 10:08

I am getting an ASCII value and I want to convert it into an integer because I know it\'s an Integer ASCII value.

int a=53; 

This is an ASC

相关标签:
8条回答
  • 2021-01-17 10:39

    If you're sure that it is an int, you can just use Integer.parseInt();

    0 讨论(0)
  • 2021-01-17 10:39

    Use Integer.parseInt(String) or if it is only a single character use: int n = (int) (_char - '0')

    0 讨论(0)
  • 2021-01-17 10:48

    If you can guarantee the string contains an integer:

     Integer.parseInt(String)
    
    0 讨论(0)
  • 2021-01-17 10:48

    Use:

    try
    {      
      int i = Integer.parseInt(StringValue);
    }
    catch (NumberFormatException nfe)
    {
      System.out.println("NumberFormatException: " + nfe.getMessage());
    }
    
    0 讨论(0)
  • 2021-01-17 10:54
    int yourInt = Integer.parseInt(yourString);
    

    http://www.cse.wustl.edu/~kjg/java/api/java/lang/Integer.html#parseInt%28java.lang.String%29

    0 讨论(0)
  • 2021-01-17 10:59
    int asciiValue = 53;
    int numericValue = Character.getNumericValue(asciiValue);
    
    System.out.println(numericValue);
    
    0 讨论(0)
提交回复
热议问题