/* -- Use VB system functions --*/
Using System;
Using System. Collections. Generic;
Using System. Text;
Using Microsoft. VisualBasic;
Namespace CaseConvert
{
/// <Summary>
/// SBC case half-width conversion class (using VB system functions)
/// Defect -- unidentifiable ,. Both of them will be recognized? /Cannot be converted \
/// </Summary>
Class CaseVBConvert
{
/// <Summary>
/// Convert the fullwidth to halfwidth
/// </Summary>
/// <Param name = "sbcCaseStr"> fullwidth string </param>
/// <Returns> halfwidth string </returns>
Public static string Convert_SBC_2_DBC (string sbcCaseStr)
{
Return Strings. StrConv (sbcCaseStr, VbStrConv. Narrow, 0 );
}
/// <Summary>
/// Convert the halfwidth to fullwidth
/// </Summary>
/// <Param name = "dbcCaseStr"> halfwidth string </param>
/// <Returns> fullwidth string </returns>
Public static string Convert_DBC_2_SBC (string dbcCaseStr)
{
Return Strings. StrConv (dbcCaseStr, VbStrConv. Wide, 0 );
}
}
}
/* -- Use C #--*/
Using System;
Using System. Collections. Generic;
Using System. Text;
Namespace CaseConvert
{
/// <Summary>
/// SBC case half-width conversion class (C #)
/// 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.
/// </Summary>
Class CaseCSConvert
{
/// <Summary>
/// Convert the fullwidth to halfwidth
/// </Summary>
/// <Param name = "sbcCaseStr"> fullwidth string </param>
/// <Returns> halfwidth string </returns>
Public static string Convert_SBC_2_DBC (string sbcCaseStr)
{
String strReturn = "";
Char [] sbcChr = sbcCaseStr. ToCharArray ();
For (int I = 0; I <sbcChr. Length; I ++)
{
If (sbcChr [I] = 12288)
{
SbcChr [I] = (char) 32;
Continue;
}
If (sbcchr [I]> 65280 & sbcchr [I] <65375)
Sbcchr [I] = (char) (sbcchr [I]-65248 );
}
Strreturn = new string (sbcchr );
Return strreturn;
}
/// <Summary>
/// Convert the halfwidth to fullwidth
/// </Summary>
/// <Param name = "dbcCaseStr"> halfwidth string </param>
/// <Returns> fullwidth string </returns>
Public static string Convert_DBC_2_SBC (string dbcCaseStr)
{
String strReturn = "";
Char [] dbcChr = dbcCaseStr. ToCharArray ();
For (int I = 0; I <dbcChr. Length; I ++)
{
If (dbcChr [I] = 32)
{
DbcChr [I] = (char) 12288;
Continue;
}
If (dbcChr [I] <127)
DbcChr [I] = (char) (dbcChr [I] + 65248 );
}
StrReturn = new string (dbcChr );
Return strReturn;
}
}
}
The preceding two common full/halfwidth character conversion functions are collected and sorted.
I personally think the latter one is more appropriate, at least it will not lead to incorrect conversion.