我得到一个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
如果你确定它是一个int,你可以使用Integer.parseInt();
如果可以保证字符串包含整数:
Integer.parseInt(String)
使用:
try
{
int i = Integer.parseInt(StringValue);
}
catch (NumberFormatException nfe)
{
System.out.println("NumberFormatException: " + nfe.getMessage());
}
你的意思是单个字符还是字符串?
char ch =
int n = Character.forDigit(ch, 10);
要么
int n = ch - '0';
使用Integer.parseInt(String)
或如果它只是一个字符使用:int n = (int) (_char - '0')
使用Integer.parseInt()
静态方法: