I am trying to eliminate unwanted namespaces, and I know there's a better way to do this. This code works, but it's remedial and redundant.
string sPattern = "xmlns:d5p1=\"http://www.w3.org/2001/XMLSchema-instance\" d5p1:nil=\"true\"";
string sPattern2 = "d5p1:nil=\"true\" xmlns:d5p1=\"http://www.w3.org/2001/XMLSchema-instance\"";
string sPattern3 = "xmlns:d2p1=\"http://www.w3.org/2001/XMLSchema-instance\" d2p1:nil=\"true\"";
string[] fString = new string[sentences.Count()];
//foreach (string str in sentences)
for(int i=0; i < sentences.Count(); i++)
{
Console.WriteLine("{0,24}", sentences[i]); // lines 0-24.
if(System.Text.RegularExpressions.Regex.IsMatch(sentences[i], sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
{
Console.WriteLine(" (match for '{0}' found)", sPattern);
eString = sentences[i].Replace(sPattern, "");
}
else if(System.Text.RegularExpressions.Regex.IsMatch(sentences[i], sPattern2, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
{
Console.WriteLine(" (match for '{0}' found)", sPattern2);
eString = sentences[i].Replace(sPattern2, "");
}
else if (System.Text.RegularExpressions.Regex.IsMatch(sentences[i], sPattern3, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
{
Console.WriteLine(" (match for '{0}' found)", sPattern3);
eString = sentences[i].Replace(sPattern3, "");
}
else
{
Console.WriteLine();
eString = sentences[i];
}
fString[i] = eString;
}
// ok, let's look at the end result
foreach(string s in fString)
{
Console.WriteLine(s);
}
// stop the app from shutting down before seeing results
Console.ReadLine();