C#利用微软自带库进行中文繁体和简体之间转换的方法
本文实例讲述了C#利用微软自带库进行中文繁体和简体之间转换的方法。分享给大家供大家参考。具体分析如下:
下面的代码是一个简单的转换范例,真正的核心转换语句只有一句话,其它的都是界面和数据相关的,使用前需要引用Microsoft.VisualBasic这个类库
///<summary>
///转繁体
///</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
protectedvoidButton1_Click(objectsender,EventArgse)
{
if(string.IsNullOrEmpty(txt_value.Text))
{
return;
}
else
{
stringvalue=txt_value.Text.Trim();
stringnewValue=StringConvert(value,"1");
if(!string.IsNullOrEmpty(newValue))
{
TextArea1.Value=newValue;
}
}
}
///<summary>
///转简体
///</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
protectedvoidButton2_Click(objectsender,EventArgse)
{
if(string.IsNullOrEmpty(txt_value.Text))
{
return;
}
else
{
stringvalue=txt_value.Text.Trim();
stringnewValue=StringConvert(value,"2");
if(!string.IsNullOrEmpty(newValue))
{
TextArea1.Value=newValue;
}
}
}
#regionIString成员
publicstringStringConvert(stringx,stringtype)
{
Stringvalue=String.Empty;
switch(type)
{
case"1"://转繁体
value=Microsoft.VisualBasic.Strings.StrConv(x,Microsoft.VisualBasic.VbStrConv.TraditionalChinese,0);
break;
case"2":
value=Microsoft.VisualBasic.Strings.StrConv(x,Microsoft.VisualBasic.VbStrConv.SimplifiedChinese,0);
break;
default:
break;
}
returnvalue;
}
#endregion
希望本文所述对大家的C#程序设计有所帮助。
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短