CSharp examples for System:String HTML
Encode Html Attribute
/***************************************************************** * Copyright (C) 2005-2006 Newegg Corporation * All rights reserved.// w w w.j av a2 s . co m * * Author: Jason Huang (jaosn.j.huang@newegg.com) * Create Date: 07/02/2008 15:12:41 * Usage: * * RevisionHistory * Date Author Description * *****************************************************************/ using System.Text; public class Main{ private static string EncodeHtmlAttribute(string strInput) { if (strInput == null) { return null; } if (strInput.Length == 0) { return string.Empty; } StringBuilder builder = new StringBuilder("", strInput.Length * 2); foreach (char ch in strInput) { if ((((ch > '`') && (ch < '{')) || ((ch > '@') && (ch < '['))) || (((ch > '/') && (ch < ':')) || (((ch == '.') || (ch == ',')) || ((ch == '-') || (ch == '_'))))) { builder.Append(ch); } else { builder.Append("&#" + ((int)ch).ToString() + ";"); } } return builder.ToString(); } }