//http://facebooktoolkit.codeplex.com/
//http://facebooktoolkit.codeplex.com/license
using System.Collections.Generic;
using System.Text;
namespace Facebook.Utility
{
/// <summary>
/// Helper functions for string manipulation
/// </summary>
public static class StringHelper
{
/// <summary>
/// Strip Non Valid XML Characters.
/// </summary>
public static string StripNonValidXMLCharacters(string s)
{
StringBuilder _validXML = new StringBuilder(s.Length, s.Length); // Used to hold the output.
char[] charArray = s.ToCharArray();
if (string.IsNullOrEmpty(s)) return string.Empty; // vacancy test.
for (int i = 0; i < charArray.Length; i++)
{
char current = charArray[i];
if ((current == 0x9) ||
(current == 0xA) ||
(current == 0xD) ||
((current >= 0x20) && (current <= 0xD7FF)) ||
((current >= 0xE000) && (current <= 0xFFFD)))
_validXML.Append(current);
}
return _validXML.ToString();
}
}
}
|