locked
problem in displaying the right single quote in c# RRS feed

  • Question

  •  Hi All,

    I have problem in displaying the right single quote

    Decimal Hex Char Description
    146 92 ’ right single quote

    The right single quote is displayed as square box.

    Thanks
    Rakesh
    Friday, August 8, 2008 2:02 PM

Answers

  •  

    string output = Encoding.Unicode.GetString(unicodebytes); does not work if we have a unicode charcter in the string like if we have a string
    as "Hello`sir" and  then the output comes as "Hello€sir".

    So the correct way of fixing is 

    ws = "Hello`Sir";

    byte[] unicodeByte = Encoding.Unicode.GetBytes(ws);

    string unicodechars = (Encoding.Default.GetString(unicodeByte)).ToString().Replace("\0", "");

    MessageBox.Show(unicodechars)

    • Marked as answer by jack 321 Friday, August 15, 2008 2:02 AM
    Thursday, August 14, 2008 2:48 PM
  • 0x92 is not a valid character code in the ISO 8859-2 code page.  Nor is it a valid codepoint in Unicode.  Use the charmap.exe applet to find character codes.
    Hans Passant.
    • Marked as answer by jack 321 Wednesday, August 13, 2008 11:20 AM
    Saturday, August 9, 2008 12:35 PM
    Moderator
  • Hi Samanyu,

    For the string “Hello Sir”, perhaps you can take a look at the following code snippet.

     

          string unicodeString = "Hello Sir";

                byte[] unicodebytes = Encoding.Unicode.GetBytes(unicodeString);

                string output = Encoding.Unicode.GetString(unicodebytes);

                string output2 = Encoding.ASCII.GetString(unicodebytes);

                string output3 = Encoding.UTF8.GetString(unicodebytes);

                Console.WriteLine(output);

                Console.WriteLine(output2);

                Console.WriteLine(output3);  

     

    After you run this code snippet, you will find that only the Unicode will work as you want ("H\e\l\l\o\S\i\r").

    Regards,

    Xun


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by jack 321 Wednesday, August 13, 2008 11:21 AM
    Tuesday, August 12, 2008 7:38 AM

All replies

  • Displaying it where?

    Friday, August 8, 2008 2:51 PM
  • Well, that just means that your font doesn't have this glyph, which isn't hugely surprising. Mine doesn't either. But this isn't a C# issue; how are you displaying the character? Try using a font that has the glyph, or use a different character instead.

    Marc


    Marc
    Friday, August 8, 2008 2:52 PM
  • For info, you can simply use:

     

    char x = '’';


    Marc
    Friday, August 8, 2008 2:55 PM

  • I  am facing the problem in displaying the special characters like
    ( ` ) right single quote in C# windows Application.

    I am using oracle as back end.
    In oracle database table the string contain the above character is stored as
    TONY ROBINSON`S CRIME AND PUNISHMENT in places in single code ( ‘ ) .

    Oracle database has following settings in nls_database_parameters

    1 NLS_NCHAR_CHARACTERSET AL16UTF16
    2 NLS_LANGUAGE ENGLISH
    3 NLS_TERRITORY UNITED KINGDOM
    4 NLS_CURRENCY #
    5 NLS_ISO_CURRENCY UNITED KINGDOM
    6 NLS_NUMERIC_CHARACTERS .,
    7 NLS_CHARACTERSET WE8ISO8859P1
    8 NLS_CALENDAR GREGORIAN
    9 NLS_DATE_FORMAT DD-MON-RR
    10 NLS_DATE_LANGUAGE ENGLISH
    11 NLS_SORT BINARY
    12 NLS_TIME_FORMAT HH24.MI.SSXFF
    13 NLS_TIMESTAMP_FORMAT DD-MON-RR HH24.MI.SSXFF
    14 NLS_TIME_TZ_FORMAT HH24.MI.SSXFF TZR
    15 NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH24.MI.SSXFF TZR
    16 NLS_DUAL_CURRENCY ?
    17 NLS_COMP BINARY
    18 NLS_LENGTH_SEMANTICS BYTE
    19 NLS_NCHAR_CONV_EXCP FALSE
    20 NLS_RDBMS_VERSION 10.1.0.5.0

    On client PC has following
    • In Regedit "HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\"
    • Under key called - KEY_OraClient10g_homeX where X is a number.
    • Value of "NLS_LANG" = "ENGLISH_UNITED KINGDOM.WE8ISO8859P1"
    But still the c# windows application displays the text properly. The special character ( ` ) is displayed as square brackets
    Saturday, August 9, 2008 12:21 PM
  • Code to display the displaying the character

     Value in DB
    ------------------
    TONY ROBINSON`S CRIME AND PUNISHMENT

    Code which gets the text from
    ----------------------------------------------
    internal static string sql = @"select prottl.prottl_title_tex from prottl join ctr on prottl.ctr_key =ctr.ctr_key where ctr.ctr_contrt_num=:P_CONTRACT_NO";


    public string getcontractTitle(Int64 contractNo) //43917
    {

    string contractTitle = "";
    try
    {


    OracleCommand qgetTitle = new OracleCommand(sql, _oraConnection);

    qgetTitle.CommandType = CommandType.Text;
    qgetTitle.Parameters.Add(new OracleParameter("P_CONTRACT_NO", OracleType.Number)).Value = contractNo;
    OracleDataReader reader = qgetTitle.ExecuteReader();

    while (reader.Read())
    {

    contractTitle = reader["prottl_title_tex"].ToString();

    }

    }
    catch (Exception Ex)
    {
    MessageBox.Show(Ex.Message);
    }
    return (contractTitle);
    }
    Saturday, August 9, 2008 12:24 PM
  • 0x92 is not a valid character code in the ISO 8859-2 code page.  Nor is it a valid codepoint in Unicode.  Use the charmap.exe applet to find character codes.
    Hans Passant.
    • Marked as answer by jack 321 Wednesday, August 13, 2008 11:20 AM
    Saturday, August 9, 2008 12:35 PM
    Moderator
  • I found a way to display right single quote in c# using the above settings.

    if we directly try find the unicode of right single quote, the it works fine
    char unichar = '\u0092';  //right single quote
    bytes[] unicodebytes = encoding.Unicode.getbytes ( unichar.Tostring());
    output string = encoding.default.getstring(unicodebytes);
    display correct unicode

    char unichar = '\u0080'; /Euro Sign
    bytes[] unicodebytes = encoding.Unicode.getbytes ( unichar.Tostring());
    output string = encoding.default.getstring(unicodebytes);
    display correct euro sign


    But for the complete string like
    string unicodeString = "Hello Sir" 
    bytes[] unicodebytes = encoding.Unicode.getbytes ( string str);
    output string = encoding.default.getstring(unicodebytes); "H\0\e\0\l\0\l\0\o\S\0\i\0\r"

    the output string only displays "H" because of addition of \0 in encoding.Unicode
    If we get the correct no of bytes like "H\e\l\l\o\S\i\r" before the actual string(encoding.default.getstring) with solve the problem.

    if someone knows how to do it, will solve the entire problem.

     

    Saturday, August 9, 2008 6:29 PM
  • Hi Samanyu,

    For the string “Hello Sir”, perhaps you can take a look at the following code snippet.

     

          string unicodeString = "Hello Sir";

                byte[] unicodebytes = Encoding.Unicode.GetBytes(unicodeString);

                string output = Encoding.Unicode.GetString(unicodebytes);

                string output2 = Encoding.ASCII.GetString(unicodebytes);

                string output3 = Encoding.UTF8.GetString(unicodebytes);

                Console.WriteLine(output);

                Console.WriteLine(output2);

                Console.WriteLine(output3);  

     

    After you run this code snippet, you will find that only the Unicode will work as you want ("H\e\l\l\o\S\i\r").

    Regards,

    Xun


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by jack 321 Wednesday, August 13, 2008 11:21 AM
    Tuesday, August 12, 2008 7:38 AM
  •  

    string output = Encoding.Unicode.GetString(unicodebytes); does not work if we have a unicode charcter in the string like if we have a string
    as "Hello`sir" and  then the output comes as "Hello€sir".

    So the correct way of fixing is 

    ws = "Hello`Sir";

    byte[] unicodeByte = Encoding.Unicode.GetBytes(ws);

    string unicodechars = (Encoding.Default.GetString(unicodeByte)).ToString().Replace("\0", "");

    MessageBox.Show(unicodechars)

    • Marked as answer by jack 321 Friday, August 15, 2008 2:02 AM
    Thursday, August 14, 2008 2:48 PM