Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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?

share|improve this question
2  
Welcome to Code Review! It's easier to help you if you also provide a bit code about how you're using this in the context of your real application. Those "number of reasons" for why you need this can be more important than you think. –  Simon Forsberg Jul 2 '14 at 11:17
1  
Calling   just “space” is confusing. It's not the normal space, it's a non-breaking space. –  svick Jul 4 '14 at 16:13

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.