C#利用微軟自帶庫進行中文繁體和簡體之間轉(zhuǎn)換的方法
更新時間:2015年04月01日 15:03:45 作者:feige
這篇文章主要介紹了C#利用微軟自帶庫進行中文繁體和簡體之間轉(zhuǎn)換的方法,涉及C#使用Microsoft.VisualBasic類庫操作中文繁簡字體轉(zhuǎn)換的技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了C#利用微軟自帶庫進行中文繁體和簡體之間轉(zhuǎn)換的方法。分享給大家供大家參考。具體分析如下:
下面的代碼是一個簡單的轉(zhuǎn)換范例,真正的核心轉(zhuǎn)換語句只有一句話,其它的都是界面和數(shù)據(jù)相關(guān)的,使用前需要引用Microsoft.VisualBasic這個類庫
/// <summary> /// 轉(zhuǎn)繁體 /// </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> /// 轉(zhuǎn)簡體 /// </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"://轉(zhuǎn)繁體 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#程序設(shè)計有所幫助。
相關(guān)文章
C#?Windows?Forms中實現(xiàn)控件之間的連接線的方法詳解
這篇文章主要為大家詳細介紹了如何在C#?Windows?Forms應(yīng)用程序中實現(xiàn)繪圖工具中多個控件之間的連接線功能,文中的示例代碼講解詳細,需要的可以參考下2024-02-02C# SynchronizationContext以及Send和Post使用解讀
這篇文章主要介紹了C# SynchronizationContext以及Send和Post使用解讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05