我得到了一个 ASCII 值,我想将其转换为整数,因为我知道它是一个整数 ASCII 值。
int a=53;
这是数字5的ASCII码值。我应该如何将其转换为整数?
我得到了一个 ASCII 值,我想将其转换为整数,因为我知道它是一个整数 ASCII 值。
int a=53;
这是数字5的ASCII码值。我应该如何将其转换为整数?
int asciiValue = 53;
int numericValue = Character.getNumericValue(asciiValue);
System.out.println(numericValue);
int yourInt = Integer.parseInt(yourString);
http://www.cse.wustl.edu/~kjg/java/api/java/lang/Integer.html#parseInt%28java.lang.String%29
使用:
try
{
int i = Integer.parseInt(StringValue);
}
catch (NumberFormatException nfe)
{
System.out.println("NumberFormatException: " + nfe.getMessage());
}
Integer.parseInt(String)
char ch =
int n = Character.forDigit(ch, 10);
或者
int n = ch - '0';
使用 Integer.parseInt(String)
或者如果只是单个字符,则使用:int n = (int) (_char - '0')
(int)
强制类型转换。 - Peter Lawrey