Method 1:
/** //
// determines whether the character is a half-width English character or punctuation
///
///
// 32 spaces
// 33-47 punctuation
// 48-57 0 ~ 9
// 58-64 punctuation
// 65-90 ~ Z
// 91-96 punctuation
// 97-122 ~ Z
// 123-126 punctuation
//
Public static bool isbjchar (char C)
{< br> int I = (INT) C;
return I >=32 & I <= 126;
}
/** // <Summary>
/// Determine whether the character is a fullwidth character or punctuation
/// </Summary>
/// <Remarks>
/// <Para> fullwidth characters-65248 = halfwidth characters </para>
/// <Para> corner space exception </para>
/// </Remarks>
Public static bool isqjchar (char C)
{
If (C = '\ u3000') return true;
Int I = (INT) C-65248;
If (I <32) return false;
Return isbjchar (char) I );
}
/** // <Summary>
/// Convert the full-width character in the string to a half-width character
/// </Summary>
Public static string tobj (string S)
{
If (S = NULL | S. Trim () = string. Empty) return S;
Stringbuilder sb = new stringbuilder (S. Length );
For (INT I = 0; I <S. length; I ++)
{
If (s [I] = '\ u3000 ')
SB. append ('\ u0020 ');
Else if (isqjchar (s [I])
SB. append (char) (INT) s [I]-65248 ));
Else
SB. append (s [I]);
}
return sb. tostring ();
}