Argentini.Halide.H3Text.HtmlEncodeSymbols C# (CSharp) Method

HtmlEncodeSymbols() public static method

public static HtmlEncodeSymbols ( string sourceString ) : String
sourceString string String to filter.
return String
        public static String HtmlEncodeSymbols(string sourceString)
        {
            StringBuilder NewVal = new StringBuilder();

            if (!String.IsNullOrEmpty(sourceString))
            {
                for (int x = 0; x < sourceString.Length; x++)
                {
                    string newCh = HttpUtility.HtmlEncode(sourceString.Substring(x, 1));
                    if (newCh == "™") { newCh = "&#153;"; } //Handle HtmlEncode's issue with the trademark symbol.

                    if (newCh.Length > 1 && (Int32)sourceString[x] > 126)
                    {
                        NewVal.Append(newCh);
                    }

                    else
                    {
                        NewVal.Append(sourceString[x]);
                    }
                }
            }

            for (int x = 0; x < HtmlSpecialCharacters.Length; x += 2)
            {
                NewVal.Replace(HtmlSpecialCharacters[x + 1], HtmlSpecialCharacters[x]);
            }

            return NewVal.ToString();
        }