将全角转换为半角 [英] Convert fullwidth to halfwidth

查看:52
本文介绍了将全角转换为半角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,如何将使用全角格式字符的字符串转换为半角格式字符?

In C#, how do I convert a string that's using fullwidth form characters into halfwidth form characters?

例如,假设下面的 userInput ,我想转换 $ c>到 Stackoverflow

For example, given userInput below, I want to convert Stackoverflow to Stackoverflow:

string userInput= "Stackoverflow";
//string userInput= "Stackoverflow";


推荐答案

您可以使用字符串.Normalize()方法:

string userInput = "Stackoverflow";
string result = userInput.Normalize(NormalizationForm.FormKC);
//result = "Stackoverflow"

请参见 DotNetFiddle

有关规范化表单的更多信息,请参见 unicode.org

More information on the Normalization Forms can be found on unicode.org.

这篇关于将全角转换为半角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆