Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 228473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:41:06+00:00 2026-05-11T19:41:06+00:00

I am generating some text to be shown on a web-site, and use HttpUtility.HtmlEncode

  • 0

I am generating some text to be shown on a web-site, and use HttpUtility.HtmlEncode to ensure it will look correct. However, this method does not appear to encode the Em Dash (it should convert it to “—”).

I have come up with a solution, but I’m sure there is a better way of doing it – some library function or something.

sWebsiteText = _
    "<![CDATA[" & _
    HttpUtility.HtmlEncode(sSomeText) & _
    "]]>"

'This is the bit which seems "hacky"'
sWebsiteText = _
    sWebsiteText.Replace(HttpUtility.HtmlDecode("&#8211;"), "&#8211;")

So my question is – how would you implement the “hacky” part?

Many thanks,

RB.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:41:07+00:00Added an answer on May 11, 2026 at 7:41 pm

    Bobince’s answer gives a solution to what seems to be your main concern : replacing your use of HtmlDecode by a more straightforward declaration of the char to replace.
    Rewrite

    sWebsiteText.Replace(HttpUtility.HtmlDecode("&#8211;"), "&#8211;")
    

    as

    sWebsiteText.Replace("\u2013", "&#x2013;")
    

    (‘\u2014’ (dec 8212) is em dash, ‘\u2013’ (dec 8211) is en dash.)
    For readability purpose it may be considered better to use “&#x2013;” rather than “&#8211;”, since the .Net declaration for the char (“\u2013”) is in hex too. But, as decimal notation seems more common in html, I personaly would prefer using “&#8211;”.
    For reuse purpose, you probably should write your own HtmlEncode function declared in a custom HttpUtility, in order to be able to call it from anywhere else in your site without duplicating it.
    (Have something like (sorry I have written it in C#, forgetting your examples were in VB):

    /// <summary>
    /// Supplies some custom processing to some HttpUtility functions.
    /// </summary>
    public static class CustomHttpUtility
    {
        /// <summary>
        /// Html encodes a string.
        /// </summary>
        /// <param name="input">string to be encoded.</param>
        /// <returns>A html encoded string.</returns>
        public static string HtmlEncode(string input)
        {
            if (intput == null)
                return null;
            StringBuilder encodedString = new StringBuilder(
                HttpUtility.HtmlEncode(input));
            encodedString.Replace("\u2013", "&#x2013;");
            // add over missing replacements here, as for &#8212;
            encodedString.Replace("\u2014", "&#x2014;");
            //...
    
            return encodedString.ToString();
        }
    }
    

    Then replace

    sWebsiteText = _
        "<![CDATA[" & _
        HttpUtility.HtmlEncode(sSomeText) & _
        "]]>"
    'This is the bit which seems "hacky"'
    sWebsiteText = _
        sWebsiteText.Replace(HttpUtility.HtmlDecode("&#8211;"), "&#8211;")
    

    With:

    sWebsiteText = _
        "<![CDATA[" & _
        CustomHttpUtility.HtmlEncode(sSomeText) & _
        "]]>"
    

    )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 111k
  • Answers 111k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Apparently not: INTO @variable_name[ ,...n] "Allows data from the columns… May 11, 2026 at 9:43 pm
  • Editorial Team
    Editorial Team added an answer I would suggest using DataTemplating to create and apply the… May 11, 2026 at 9:43 pm
  • Editorial Team
    Editorial Team added an answer There are several, including GMP, but for speed, the best… May 11, 2026 at 9:43 pm

Related Questions

I'm trying to figure out a simple to draw some text in OpenGL. My
I want to write an application that consumes RSS. I want to be able
Thanks for reading this. I am dynamically generating some data which includes a select
I want to verify that the items in my ListBox are displayed correctly in
I am working on an ASP.Net web application that must print dynamically created labels

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.