Method 1:
Copy codeThe Code is as follows: // <summary>
/// Chinese Character tool class
/// </Summary>
Private const int LOCALE_SYSTEM_DEFAULT = 0x0800;
Private const int LCMAP_SIMPLIFIED_CHINESE = 0x02000000;
Private const int LCMAP_TRADITIONAL_CHINESE = 0x04000000;
[DllImport ("kernel32", CharSet = CharSet. Auto, SetLastError = true)]
Private static extern int LCMapString (int Locale, int dwMapFlags, string lpSrcStr, int cchSrc, [Out] string lpDestStr, int cchDest );
/// <Summary>
/// Convert characters to simplified Chinese
/// </Summary>
/// <Param name = "source"> enter the string to be converted </param>
/// <Returns> string after conversion </returns>
Public static string ToSimplified (string source ){
String target = new String ('', source. Length );
Int ret = LCMapString (LOCALE_SYSTEM_DEFAULT, LCMAP_SIMPLIFIED_CHINESE, source, source. Length, target, source. Length );
Return target;
}
/// <Summary>
/// Convert the lecture character to traditional Chinese
/// </Summary>
/// <Param name = "source"> enter the string to be converted </param>
/// <Returns> string after conversion </returns>
Public static string ToTraditional (string source)
{
String target = new String ('', source. Length );
Int ret = LCMapString (LOCALE_SYSTEM_DEFAULT, LCMAP_TRADITIONAL_CHINESE, source, source. Length, target, source. Length );
Return target;
}
Call the ToTraditiona method above and it will be OK ~ In addition, the same method of use ~
Method 2: (recommended)
① Right-click "add reference" in the corresponding folder in solution manager ---- select Microsoft. VisualBasic under. net reference;
② Add the namespace using Microsoft. VisualBasic to the aspx. cs file you want to implement the conversion function.
③ The following method can be used to directly implement conversion, which is very convenient! One sentence is enough ~ Therefore, this method is recommended.Copy codeThe Code is as follows: string s = "traditional ";
S = Strings. StrConv (s, VbStrConv. Wide, 0); // halfwidth to fullwidth
S = Strings. StrConv (s, VbStrConv. TraditionalChinese, 0); // convert simplified to traditional
S = Strings. StrConv (s, VbStrConv. ProperCase, 0); // uppercase
S = Strings. StrConv (s, VbStrConv. Narrow, 0); // returns the halfwidth.
S = Strings. StrConv (s, VbStrConv. SimplifiedChinese, 0); // convert traditional to simplified