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