C# 实现繁体字和简体字之间的转换

来源:互联网 发布:react.js 入门微盘 编辑:程序博客网 时间:2024/04/27 22:27

4. 最后呢就是在aspx.cs中实现了,代码如下:

View Code
复制代码
 1 /// <summary> 2 /// 转繁体 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="e"></param> 6     protected void Button1_Click(object sender, EventArgs e) 7     { 8         if (string.IsNullOrEmpty(txt_value.Text)) 9         {10             return;11         }12         else13         {14             string value = txt_value.Text.Trim();15             string newValue = StringConvert(value, "1");16             if (!string.IsNullOrEmpty(newValue))17             {18                 TextArea1.Value = newValue;19             }20         }21     }22     /// <summary>23 /// 转简体24 /// </summary>25 /// <param name="sender"></param>26 /// <param name="e"></param>27     protected void Button2_Click(object sender, EventArgs e)28     {29         if (string.IsNullOrEmpty(txt_value.Text))30         {31             return;32         }33         else34         {35             string value = txt_value.Text.Trim();36             string newValue = StringConvert(value, "2");37             if (!string.IsNullOrEmpty(newValue))38             {39                 TextArea1.Value = newValue;40             }41         }42     }43 44     #region IString 成员45 46     public string StringConvert(string x, string type)47     {48         String value = String.Empty;49         switch (type)50         {51             case "1"://转繁体52                 value =  Microsoft.VisualBasic.Strings.StrConv(x, Microsoft.VisualBasic.VbStrConv.TraditionalChinese,0);53                 break;54             case "2":55                 value = Microsoft.VisualBasic.Strings.StrConv(x, Microsoft.VisualBasic.VbStrConv.SimplifiedChinese, 0);56                 break;57             default:58                 break;59         }60         return value;61     }62 63     #endregion
原创粉丝点击