Asp.net 10-to-hexadecimal string

Source: Internet
Author: User

Asp tutorial. net 10-to-hexadecimal string conversion
Public string strtohex (string mstr) // return the processed hexadecimal string
    {
Return bitconverter. tostring (
Asciiencoding. default. getbytes (mstr). replace ("-","");
}/* Strtohex */

Convert a hexadecimal string to a decimal string
Public string hextostr (string mhex) // returns the string in hexadecimal notation.
    {
Mhex = mhex. replace ("","");
If (mhex. length <= 0) return "";
Byte [] vbytes = new byte [mhex. length/2];
For (int I = 0; I <mhex. length; I + = 2)
If (! Byte. tryparse (mhex. substring (I, 2), numberstyles. hexnumber, null, out vbytes [I/2])
Vbytes [I/2] = 0;
Return asciiencoding. default. getstring (vbytes );
}/* Hextostr */

 

Convert string to wide character

Public static string stringtowchar (string s)
    {
Stringbuilder outs = new stringbuilder ();
Foreach (char item in s)
        {
If (isencoding (item) // determines whether the code is encoded.
            {
Outs. append (string. format ("u {0: x4}", (int) item ));
            }
Else // not Chinese
            {
Outs. append (item );
            }
        }
Return outs. tostring ();
    }

Private static bool isencoding (char cha)
    {
String nonencodingchats = "abcdefghijklmnopqrstuvwxyz0123456789 '! @ # $ % ^ & * () _ + |-=,./; '[] {}:<>? ";
Return nonencodingchats. indexof (cha) =-1;
    }

 

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.