惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
Hugging Face - Blog
Hugging Face - Blog
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
D
Docker
C
Cyber Attacks, Cyber Crime and Cyber Security
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
T
Tenable Blog
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
The Hacker News
The Hacker News
Project Zero
Project Zero
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Scott Helme
Scott Helme
A
About on SuperTechFans
WordPress大学
WordPress大学
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
G
GRAHAM CLULEY
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Schneier on Security

博客园 - ant520

GNS3的使用2 SecureCRT 应用 sql 2000 修复问题 GNS3的使用 虚拟机-文件 无法显示隐藏文件的解决方法 看QQ是否在线 百度地图指南 sql 知识摘录 配置静态路由使用出站接口和下一跳IP的差别 如何计算冲突域和广播域-图解分析 240多个jQuery插件 C#中使用SQLite数据库 Visual studio 配置文件下载 SQL2000 安装,挂起 委托/事件 在口上打对钩√ DataTab转换XML XML转换DataTable 的类[转] excel 2003系列
全角转半角与半角转全角
ant520 · 2011-01-18 · via 博客园 - ant520
1.全角:指一个字符占用两个标准字符位置。汉字字符和规定了全角的英文字符及国标GB2312-80中的图形符号和特殊字符都是全角字符。一般的系统命令是不用全角字符的,只是在作文字处理时才会使用全角字符。
2.半角:指一字符占用一个标准的字符位置。通常的英文字母、数字键、符号键都是半角的,半角的显示内码都是一个字节。在系统内部,以上三种字符是作为基本代码处理的,所以用户输入命令和参数时一般都使用半角。
3.全角与半角在计算机中的表示:据我所知,全角的第一个字节是163(我用-93),然后第二个字节与半角相差128。全角空格和半角空格也要考虑进去。
4.C/C++版本:
 
string ToDBS(string str) { 
    string result = ""; 
    unsigned char tmp; unsigned char tmp1; 
    for (unsigned int i = 0; i < str.length(); i++) { 
        tmp = str[i]; 
        tmp1 = str[i + 1]; 
        cout << "uchar:" << (int) tmp << endl; 
        if (tmp == 163) {///第一个字节是163,标志着是全角字符 
            result += (unsigned char) str[i + 1] - 128; 
            i++; 
            continue; 
        } else if (tmp > 163) {//汉字 
            result += str.substr(i, 2); 
            i++; 
            continue; 
        } else if (tmp == 161 && tmp1 == 161) {///处理全角空格 
            result += ""; 
            i++; 
        } else { 
            result += str.substr(i, 1); } } return result; 
} 
 
5.C#版本:        
     /// <summary> 
        /// 转全角的函数(SBC case) 
        /// </summary> 
        /// <param name="input">任意字符串</param> 
        /// <returns>全角字符串</returns> 
        ///<remarks> 
        ///全角空格为12288,半角空格为32 
        ///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248 
        ///</remarks>         
        public static string ToSBC(string input) 
        { 
            //半角转全角: 
            char[] c = input.ToCharArray(); 
            for (int i = 0; i < c.Length; i++) 
            { 
                if (c[i] == 32) 
                { 
                    c[i] = (char)12288; 
                    continue; 
                } 
                if (c[i] < 127) 
                    c[i] = (char)(c[i] + 65248); 
            } 
            return new string(c); 
        } 
 
 
         
        /// <summary> 
        /// 转半角的函数(DBC case) 
        /// </summary> 
        /// <param name="input">任意字符串</param> 
        /// <returns>半角字符串</returns> 
        ///<remarks> 
        ///全角空格为12288,半角空格为32 
        ///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248 
        ///</remarks> 
        public static string ToDBC(string input) 
        { 
            char[] c = input.ToCharArray(); 
            for (int i = 0; i < c.Length; i++) 
            { 
                if (c[i] == 12288) 
                { 
                    c[i] = (char)32; 
                    continue; 
                } 
                if (c[i] > 65280 && c[i] < 65375) 
                    c[i] = (char)(c[i] - 65248); 
            } 
            return new string(c); 
        }