. NET simple and traditional conversions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.