Asp. NET tip: Full-width character conversion to half angle

Source: Internet
Author: User
Tags bool
Asp.net| Skills | conversion

Method One:
/**////<summary>
Determines whether a character is a half-width character or punctuation
</summary>
<remarks>
32 spaces
33-47 punctuation
48-57 0~9
58-64 punctuation
65-90 a~z
91-96 punctuation
97-122 a~z
123-126 punctuation
</remarks>
public static bool Isbjchar (char c)
{
int i = (int) c;
return i >= && i <= 126;
}

/**////<summary>
To determine whether a character is a full-width character or punctuation
</summary>
<remarks>
<para> full-width characters-65248 = half-width characters </para>
<para> Full Space Exception </para>
</remarks>
public static bool Isqjchar (char c)
{
if (c = = ' \u3000 ') return true;

int i = (int) c-65248;
if (I <) return false;
Return Isbjchar ((char) i);
}

/**////<summary>
Converts full-width characters in a string to half corners
</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 ();
}

Method Two:
Add a Microsoft Visual Basic.NET Runtime Reference.
Console.WriteLine (Microsoft.VisualBasic.Strings.StrConv ("ABCDEFG", VbStrConv.Narrow, 0));



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.