.NET ez 2013-01-25
之前有一篇 簡體 繁體 轉換,現在多了大小寫轉換,方式差不多,依樣是呼叫 Microsoft.VisualBasic 即可達成。
程式碼如下:
using System;
using System.Text;
using Microsoft.VisualBasic;
namespace StrConv
{
public partial class Default : System.Web.UI.Page
{
public StringBuilder SB = new StringBuilder();
protected string TestStr = "測試文字abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_+~`-=[]\\{}:\";'<>?,./|";
protected void Page_Load(object sender, EventArgs e)
{
ConvertStrConv();
}
private void ConvertStrConv()
{
//不執行轉換
DisplayList(VbStrConv.None.ToString(), Strings.StrConv(TestStr, VbStrConv.None));
//將字串轉換為大寫字元。
DisplayList(VbStrConv.Uppercase.ToString(), Strings.StrConv(TestStr, VbStrConv.Uppercase));
//將字串轉換為小寫字元。
DisplayList(VbStrConv.Lowercase.ToString(), Strings.StrConv(TestStr, VbStrConv.Lowercase));
//將字串中每個單字的第一個字母轉換為大寫。
DisplayList(VbStrConv.ProperCase.ToString(), Strings.StrConv(TestStr, VbStrConv.ProperCase));
//將字串中的半形字元轉換成全形字元。
DisplayList(VbStrConv.Wide.ToString(), Strings.StrConv(TestStr, VbStrConv.Wide).Replace("\\", "\"));
//將字串中的全形字元轉換成半形字元。
DisplayList(VbStrConv.Narrow.ToString(), Strings.StrConv(TestStr, VbStrConv.Narrow));
//將繁體中文字元轉換成簡體中文。
DisplayList(VbStrConv.SimplifiedChinese.ToString(), Strings.StrConv(TestStr, VbStrConv.SimplifiedChinese, 2052));
//將簡體中文字元轉換成繁體中文。
DisplayList(VbStrConv.TraditionalChinese.ToString(), Strings.StrConv(TestStr, VbStrConv.TraditionalChinese, 1028));
}
private void DisplayList(string strVbStrConvName, string strInValue)
{
SB.AppendLine(String.Format("VbStrConv:{0} 轉換後 {1} <BR/><BR/>", strVbStrConvName, strInValue));
}
}
}標籤: .NET
本文章網址:
https://www.ez2o.com/Blog/Post/csharp-TraditionalChinese-SimplifiedChinese-VbStrConv
https://www.ez2o.com/Blog/Post/316
https://www.ez2o.com/Blog/Post/csharp-TraditionalChinese-SimplifiedChinese-VbStrConv
https://www.ez2o.com/Blog/Post/316
