Convert Arabic char into Unicode RRS feed

  • Question

  • User-1200238706 posted
    I am trying to convert Arabic char into Unicode and then save it into Sql Server DB. I am using Asp.net C#. 
    Can someone help me how to do this in a simple way.
    Thursday, July 14, 2005 5:19 AM

All replies

  • User933406816 posted
    .net strings are already unicode strings. What are you trying to do exactly?
    Tuesday, July 19, 2005 5:36 AM
  • User-1200238706 posted
    I wanted to convert arabic data  into Hex format:
    into :



    Tuesday, July 19, 2005 10:54 AM
  • User418900235 posted
    Dear qnabeel;

    to store unicode text just do this:
    1 - open your desired webform in visual studio.net
    2 - go to html view.
    3 - hit file -> advance save option -> Unicode(utf8 with signiture) codepage 65001

    it is enough to having ability to save the unicode chars in SqlServer DB
    but if you want to do the job yet, here it is :

    i needed it for some persian(utf-8) URL parameter support and
    it takes 3 hour for me!

    1 - take a look at this beautiful article and download the sourcecode.
         it contains a class to working with HexEncoding(like UTF8Encoding)

    2 - see below souece code that i used.

    // ---------------------------------------------------------------------------------------------------
    // Convert a unicode to Hex

    private static string ToHexString(char chr)


    UTF8Encoding utf8 = new UTF8Encoding();

    byte[] encodedBytes = utf8.GetBytes(chr.ToString());

    StringBuilder builder = new StringBuilder();

    for(int index=0; index<encodedBytes.Length; index++)


    builder.AppendFormat("%{0}",Convert.ToString(encodedBytes[index], 16));


    return builder.ToString();


    // -------------------------------------------------------------------------------------------
    // convert it back to unicode

    private static string ToStringHex(string hexChar)


    string hexString = hexChar;

    int discarded;

    byte[] byteArray = HexEncoding.GetBytes(hexString, out discarded);

    return UTF8Encoding.UTF8.GetString(byteArray);


    // ---------------------------------------------------------------------------------------------------
    dont hesitate to ask again, i will help you as much as i can

    hope this little can help.

    "by the way dont forget to add reference to System.Text"

    Tuesday, August 9, 2005 7:29 AM
  • User1416329745 posted
    In SQL Server you need NCHAR, NVarchar and NText to store unicode, the former are 4000 limit while the later can grow to 2gig but Unicode in SQL Server is multi bytes so the later can grow to 1gig.  Run a search for Unicode collation in SQl Server BOL(books online).  Hope this helps.
    Wednesday, August 10, 2005 3:52 PM
  • User208798261 posted

    Did you get any resolution?

    Sunday, September 18, 2011 9:30 AM