public static string GetWhiteSpaceXml(string stringToConvert)
{
try
{
ArrayList matchList = new ArrayList();
string pat = @"\s{2,}";
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
Match m = r.Match(stringToConvert);
while (m.Success)
{
WhiteSpaceHelper w = new WhiteSpaceHelper();
for(int i=0; i<m.Length; i++)
w.Value += " ";
w.Replacement = "<ws id=\""+m.Length.ToString()+"\"/>";//GetXmlWhiteSpace(m.Length);
matchList.Add(w);
m = m.NextMatch();
}
foreach(WhiteSpaceHelper w in matchList)
stringToConvert = stringToConvert.Replace(w.Value, w.Replacement);
}
catch(Exception)
{
//unhandled, only whitespaces arent displayed correct
}
return stringToConvert;
}