C#利用微软自带库进行中文繁体和简体之间转换的方法_C#教程-查字典教程网
C#利用微软自带库进行中文繁体和简体之间转换的方法
C#利用微软自带库进行中文繁体和简体之间转换的方法
发布时间:2016-12-28 来源:查字典编辑
摘要:本文实例讲述了C#利用微软自带库进行中文繁体和简体之间转换的方法。分享给大家供大家参考。具体分析如下:下面的代码是一个简单的转换范例,真正的...

本文实例讲述了C#利用微软自带库进行中文繁体和简体之间转换的方法。分享给大家供大家参考。具体分析如下:

下面的代码是一个简单的转换范例,真正的核心转换语句只有一句话,其它的都是界面和数据相关的,使用前需要引用Microsoft.VisualBasic这个类库

/// <summary> /// 转繁体 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txt_value.Text)) { return; } else { string value = txt_value.Text.Trim(); string newValue = StringConvert(value, "1"); if (!string.IsNullOrEmpty(newValue)) { TextArea1.Value = newValue; } } } /// <summary> /// 转简体 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button2_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txt_value.Text)) { return; } else { string value = txt_value.Text.Trim(); string newValue = StringConvert(value, "2"); if (!string.IsNullOrEmpty(newValue)) { TextArea1.Value = newValue; } } } #region IString 成员 public string StringConvert(string x, string type) { String value = 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; } return value; } #endregion

希望本文所述对大家的C#程序设计有所帮助。

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新C#教程学习
    热门C#教程学习
    编程开发子分类