栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

ASCII编码表 以及怎么获取ASCII码 #Java #Python #C++ #JavaScript

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ASCII编码表 以及怎么获取ASCII码 #Java #Python #C++ #JavaScript

其中最常用:

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 
#include 
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));
});
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/777555.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号