Java 将字符串转换为十进制( ASCII )?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19509261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Conversion of String to decimal ( ASCII )?
提问by reinhard.lee
String buffer = "c";
Conversion by Decimal. I wanna change buffer value to decimal value.
按十进制转换。我想将缓冲区值更改为十进制值。
In ASCII Table
DEC HEX CHAR
99 63 c
So, Finally
buffer -> 99 ( return value int or String and something )
所以,最后
buffer -> 99 ( return value int or String and something )
How Can I Change that value?
如何更改该值?
Integer.parseInt(buffer, 12) -> returns 12
But I wanna get 99
但我想得到 99
is it Possible to conversion?
可以转换吗?
采纳答案by Ankur
String buffer = "c";
char ch = buffer.charAt(0);
System.out.println((int)ch);
This should do it.
这应该这样做。
回答by Scary Wombat
try
尝试
System.out.println((int)ch);
where ch is a char
其中 ch 是一个字符
Of course in you code you have a string, so maybe you need to get the first char or something
当然在你的代码中你有一个字符串,所以也许你需要得到第一个字符或其他东西
回答by Sandesh Vaze
String buffer = "abc";
for(int i=0;i<buffer.length();i++)
{
System.out.println((int)buffer.charAt(i));
}