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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - 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); 
        }