ASP. NET tips: Convert full-width characters to half-width characters

Source: Internet
Author: User

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 ();
}

Related Article

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.