Keep a record of it, lest you look everywhere
Method One
<summary>
Chinese Characters Tool class
</summary>
public static class Chinesestringutility {
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 convert </param>
<returns> string after conversion is complete </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 to Traditional Chinese speaking characters
</summary>
<param name= "Source" > enter the string to convert </param>
<returns> string after conversion is complete </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;
}
}
Method Two
In VS, there is a classic Microsoft.VisualBasic.dll VB Class Library, according to the official description:
It provides simple, intuitive access to many. NET Framework classes, enabling you to write operations and method code that can interact with computers, applications, settings, resources, and so on.
This time, write a more classical things, Simplified Chinese to traditional methods of operation, to operate, the first reference class library.
We can refer to Microsoft.VisualBasic.dll in the project.
To implement the simplified traditional conversion method:
Microsoft.VisualBasic.Strings.StrConv (String str, VbStrConv Conversion, int LocaleID);
Simple and complex conversions, except that the enumeration values are not the same
Simplified to Traditional: Microsoft.VisualBasic.Strings.StrConv (String str, vbstrconv.traditionalchinese,0)
Traditional to Simplified: Microsoft.VisualBasic.Strings.StrConv (String str vbstrconv.simplifiedchinese,0)
STR: The String expression to convert.
Conversion:Microsoft.VisualBasic.VbStrConv. An enumeration value that specifies the type of transformation to perform.
The Localeid:localeid value (if it differs from the system LocaleID value). (The system LocaleID value is the default value.) )
How is it actually used? So let's do a test.
Class Program
{
static void Main (string[] args)
{
Console.Write (Microsoft.VisualBasic.
Strings.strconv ("Blog Park",
Microsoft.VisualBasic.VbStrConv.TraditionalChinese, 0));
Console.read ();
}
}
Original link: http://blog.csdn.net/weiqian000/article/details/5565415
. NET simple and traditional conversions