Conversion methods between C # string and hex

Source: Internet
Author: User

///<summary>
///< functions: Encode>
///Effect: Converts a string content into a 16-encoded data encoding, which is the reverse process decode
///parameter description:
/// Strencode the original string that needs to be transformed
///the process of converting a character directly into a Unicode character, such as the number "3"-->0033, the Chinese character "I"-->u+6211
/// The process of function decode is the inverse process of encode.
///</summary>
///<param name= "Strencode" ></PARAM>
///<returns></returns
public static string Encode (String strencode)
{
    string strreturn = "";//  Store converted encoding
    foreach (Short shortx in Strencode.tochararray ())
    {
         Strreturn + = Shortx. ToString ("X4");
   }
    return strreturn;
}


///<summary>
///< functions: Decode>
///role: Converting 16-encoded data into a string is a encode inverse procedure
///</summary>
///<param name= "Strdecode" ></PARAM>
///<returns></returns>
public static string Decode (String strdecode)
{
    string sresult = ";
    for (int i = 0; i < STRDECODE.LENGTH/4 i++)
    {
&NBSP;&NBSP;&NBSP;&NBSP;&N bsp;   Sresult + = (char) short. Parse (Strdecode.substring (i * 4, 4), global::system.globalization.numberstyles.hexnumber);
   }
    return sresult;
}

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.