C Chinese simplified to traditional implementation code
- 2020-05-09 19:05:36
- OfStack
Method 1:
/// <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>
/// Converts characters to simplified Chinese
/// </summary>
/// <param name="source"> Enter the string you want to convert </param>
/// <returns> The converted string </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>
/// To convert characters to traditional Chinese
/// </summary>
/// <param name="source"> Enter the string you want to convert </param>
/// <returns> The converted string </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;
}
calls the ToTraditiona method above for OK
Method 2 :(recommended)
In the corresponding folder in the solution manager, right-click "add reference" -- select Microsoft.VisualBasic under the net reference;
Add a namespace to the aspx.cs file you want to convert: using Microsoft.VisualBasic
Through the following method can be directly converted, very convenient! 1 sentence is enough ~ so I recommend this method
string s = " traditional ";
s = Strings.StrConv(s, VbStrConv.Wide, 0); // Half the Angle goes to the whole Angle
s = Strings.StrConv(s, VbStrConv.TraditionalChinese, 0); // Simplified to traditional
s = Strings.StrConv(s, VbStrConv.ProperCase , 0); // Capital letter
s = Strings.StrConv(s, VbStrConv.Narrow , 0); // Let's turn the whole Angle half an Angle
s = Strings.StrConv(s, VbStrConv.SimplifiedChinese, 0); // Traditional to simplified Chinese