Server.HTMLDecode doesn't decode char 345

Discussion in 'ASP .Net' started by Jonas Åkermark, Aug 2, 2005.

  1. Hello!

    I have a problem decoding the czech character:

    The HTML code for this character is ř but when running
    Server.HTMLdecode on that string it just returns ř instead of the real
    char. (It works on a lot of other characters)
    I need to decode this string in order to render an image with this character
    as a part of a headline.

    Can anyone help me with this issue, or is it maybe a bug?

    /kindest regards, Jonas
    Jonas Åkermark, Aug 2, 2005
    1. Advertisements

  2. Jonas Åkermark

    Karl Seguin Guest

    This works fine for me:

    My web.config specifies:
    <globalization requestEncoding="utf-8" responseEncoding="utf-8" />

    maybe yours is using something else?

    Karl Seguin, Aug 2, 2005
    1. Advertisements

  3. Maybe it is because I'm usning the Server object in a function in a non web
    environment - a regular class:

    string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
    text );

    where the text property sometimes contains the char ř

    Is there some way that I can tell the HtmlDecode which encoding to use?

    Jonas Åkermark, Aug 2, 2005
  4. Jonas Åkermark

    Karl Seguin Guest

    i don't think that's your problem (although within a class, there's no
    reason not to use System.Web.HttpUtility.HtmlDecode which decouples your
    class from the context (ie, it can be reused outside of the web)).

    All HtmlDecode does in the case of a numeric value (such as 345), is:

    char c1 = (char) ((ushort) int.Parse("345"));

    Is your page encoding set to utf-8? (if you put tracing on, at the top of
    the trace information it says the encoding).l


    MY ASP.Net tutorials - New and Improved (yes, the popup is
    annoying) - unofficial newsgroup FAQ (more to
    Karl Seguin, Aug 2, 2005
  5. Yes the encoding is set ut utf-8

    the strange thing is that the decodedText property still contains the
    "ř" string after HtmlDecode

    Nevermind, thanks for your explanation of the HtmlDecode, I have now created
    a SpecialDecode function instead that works fine

    private static string SpecialDecode(string decodedText)
    string tmpResult = decodedText;
    bool found = true;
    if( tmpResult.IndexOf("&#") > -1 )
    string chars = tmpResult.Substring( tmpResult.IndexOf("&#")+2, 3);
    char c1 = (char) ((ushort) int.Parse(chars));
    tmpResult = tmpResult.Replace("&#" + chars + ";", c1.ToString());
    found = false;

    return tmpResult;
    Jonas Åkermark, Aug 2, 2005
  6. Jonas Åkermark

    Joerg Jooss Guest

    Numeric references are based on Unicode code points, thus
    requestEncoding and responseEncoding don't apply.

    Joerg Jooss, Aug 2, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.