1. Custom Methods
/** // <Summary>
/// Function for converting the fullwidth (SBC case)
/// </Summary>
/// <Param name = "input"> any string </param>
/// <Returns> fullwidth string </returns>
/// <Remarks>
/// The full-width space is 12288, and the half-width space is 32.
/// The relationship between the half-width (33-126) of other characters and the full-width (65281-65374) is as follows: the difference is 65248.
/// </Remarks>
Public string ToSBC (string input)
{
// Halfwidth to fullwidth:
Char [] c = input. ToCharArray ();
For (int I = 0; I <c. Length; I ++)
{
If (c [I] = 32)
{
C [I] = (char) 12288;
Continue;
}
If (c [I] <127)
C [I] = (char) (c [I] + 65248 );
}
Return new string (c );
}
/** // <Summary>
/// Returns a function (DBC case)
/// </Summary>
/// <Param name = "input"> any string </param>
/// <Returns> halfwidth string </returns>
/// <Remarks>
/// The full-width space is 12288, and the half-width space is 32.
/// The relationship between the half-width (33-126) of other characters and the full-width (65281-65374) is as follows: the difference is 65248.
/// </Remarks>
Public string ToDBC (string input)
{
Char [] c = input. ToCharArray ();
For (int I = 0; I <c. Length; I ++)
{
If (c [I] = 12288)
{
C [I] = (char) 32;
Continue;
}
If (c [I]> 65280 & c [I] <65375)
C [I] = (char) (c [I]-65248 );
}
Return new string (c );
}
2,Use the Microsoft. VisualBasic class library
Add reference Microsoft. visualBasic. dll, you can directly use VB in the C # program. NET rich functions 1 // command line compilation: csc/r: Microsoft. visualBasic. dll Test. cs
Using Microsoft. VisualBasic;
Class Test
{
Static void Main ()
{
String s = "blog garden-a you [http://conquer.cnblogs.com]";
System. Console. WriteLine (s );
S = Strings. StrConv (s, VbStrConv. Wide, 0); // halfwidth to fullwidth
S = Strings. StrConv (s, VbStrConv. TraditionalChinese, 0); // convert simplified to traditional
System. Console. WriteLine (s );
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
System. Console. WriteLine (s );
}
}