# Thursday, August 05, 2010
« Tip of the Day: T-SQL Script to rename b... | Main | Tip of the Day: The evolution of dynamic... »
Ever need to HTML Encode a string? This useful extension method will do it for you:
    /// <summary>
    /// Extension method to HTML encode any string characters with ASCII > 127
    /// </summary>
    /// <param name="str">string to be encoded</param>
    /// <returns>Encoded string</returns>
    public static string ToHtml(this string str) 
    { 
        return string.Join("", str.ToCharArray().Select(c => (int)c > 127 ? "&#" + (int)c + ";" : c.ToString()).ToArray()); 
    }





Comments are closed.