2
\$\begingroup\$

I have to store various HTML named character references for the following purposes:

  1. Escaping special characters myStringBuilder.Replace("À", WebHelper.Agrave)

  2. Insert spaces in legacy reports ReportButtons.Controls.Add(New LiteralControl(WebHelper.Space))

This is the way I used to store until now:

public static class WebHelper
{
 #region [ Fields ]
 public const string Agrave = "À";
 public const string Space = " ";
 #endregion
}

Is this Single-Generic-Helper-Class the best way to solve this problem? Should all my programs reference it?

Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Jul 2, 2014 at 10:01
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Calling   just "space" is confusing. It's not the normal space, it's a non-breaking space. \$\endgroup\$ Commented Jul 4, 2014 at 16:13

1 Answer 1

2
\$\begingroup\$

Why not just use the Server.HtmlEncode function?

Here is a brief description of what it does:

Any ASCII code character whose code is greater-than or equal to 0x80 is converted to &#<number>, where <number> is the ASCII character value.

It also converts common ascii characters such as <, >, &, and " to their html character references.

answered Jul 2, 2014 at 21:17
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.