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

推荐订阅源

N
News and Events Feed by Topic
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
Jina AI
Jina AI
H
Help Net Security
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
L
LangChain Blog
Recorded Future
Recorded Future
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
GbyAI
GbyAI
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
M
MIT News - Artificial intelligence
爱范儿
爱范儿
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
B
Blog
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
MongoDB | Blog
MongoDB | Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
The Cloudflare Blog
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
D
DataBreaches.Net
博客园 - 【当耐特】
T
Troy Hunt's Blog
V
Visual Studio Blog
V2EX - 技术
V2EX - 技术
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google Online Security Blog
Google Online Security Blog
The GitHub Blog
The GitHub Blog

博客园 - 林骄

Android note 2010.08.02 v2 2010.08.03 Android note Android Note 2010.08.02 Android Note 2011.08.01 [Biztalk]问题集 - 林骄 - 博客园 Winform导出Excel Excel单元格颜色 判断系统版本 ListView && XmlReader How to open a folder with explorer - 林骄 Print Can't open Infragistics help document How to get local machine date format.如何获取本机时间格式 cannot open user default database WebService Tips Windows Service 装机备忘 Db2中的时间
中文全半角转换
林骄 · 2009-08-16 · via 博客园 - 林骄

 public static void Example(string userInput)
        
{
            
string sbc = userInput.ToSBC(); //转全角
            
//具体操作,如存入数据库 
            string dbc = userInput.ToDBC();//转半角
            
//具体操作,如存入数据库 
        }

        
/**//// <summary>
        
/// 转全角(SBC case)
        
/// </summary>
        
/// <param name="input">任意字符串</param>
        
/// <returns>全角字符串</returns>

        public static string ToSBC(this 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>

        public static string ToDBC(this 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);
        }