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

