C#應用微軟自帶庫停止中文繁體和簡體之間轉換的辦法。本站提示廣大學習愛好者:(C#應用微軟自帶庫停止中文繁體和簡體之間轉換的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是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#法式設計有所贊助。