其中最常用:
0 – 9 : 48~57
A – Z :65~90
a – z : 97~122
java中如何获取字符的ASCII码
java中使用Integer.valueOf(char c)方法可以直接获取一个字符的ASCII码,比如:
public class ASCIITest { public static void main(String[] args) { char a='a'; char A='A'; int a_ascii=Integer.valueOf(a); int A_ascii=Integer.valueOf(A); System.out.println("字符"+a+"的ASCII码为:"+a_ascii); System.out.println("字符"+A+"的ASCII码为:"+A_ascii); System.out.println(A-2); System.out.println(A_ascii-a_ascii); } }
C++中如何获取字符的ASCII码
c++和java类似
#include <iostream> #include <cstdio> using namespace std; int main() { char ch1 = 'a'; char ch2 = 'A'; cout << int(ch1) << endl; //将字符强转成整形数,也就是我们能看懂的十进制数 cout << int(ch2) << endl; return 0; }
python中如何获取字符的ASCII码
# python program to print ASCII # value of a given character # Assigning character to a variable char_var = 'A' # printing ASCII code print("ASCII value of " + char_var + " is = ", ord(char_var)) char_var = 'x' # printing ASCII code print("ASCII value of " + char_var + " is = ", ord(char_var)) char_var = '9' # printing ASCII code print("ASCII value of " + char_var + " is = ", ord(char_var))
JavaScript中如何获取字符的ASCII码
var s = 'A'; console.log(s.charCodeAt(0)); // 65 console.log(String.fromCharCode(65)); // 'A' 'apple'.split('').forEach(function (c) { console.log(c + ': ' + c.charCodeAt(0)); });
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之家整理,本文链接:https://www.bmabk.com/index.php/post/73535.html