I have a string from which I need to strip all HTML 以及XML. I am not really good with regular expressions. For HTML I found some really useful code:
snippet = Regex.Replace(snippet, "<.*?>", "");
目前,我正为“XML”努力:
while (snippet.IndexOf("<xml>") != -1)
{
int startLoc = snippet.IndexOf("<xml>");
int endLoc = snippet.IndexOf("</xml>");
snippet = snippet.Remove(startLoc, (endLoc - startLoc) + 6);
}
while (snippet.IndexOf("<style>") != -1)
{
int startLoc = snippet.IndexOf("<style>");
int endLoc = snippet.IndexOf("</style>");
snippet = snippet.Remove(startLoc, (endLoc - startLoc) + 8);
}
// only required for chrome 以及IE
// removes - <object classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id="ieooui">
while (snippet.IndexOf("<object") != -1)
{
int startLoc = snippet.IndexOf("<object");
int endLoc = snippet.IndexOf("id="ieooui">");
snippet = snippet.Remove(startLoc, (endLoc - startLoc) + 12);
}
// removes - <object id="ieooui" classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D">
while (snippet.IndexOf("<object") != -1)
{
int startLoc = snippet.IndexOf("<object");
int endLoc = snippet.IndexOf("classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D"");
snippet = snippet.Remove(startLoc, (endLoc - startLoc) + 52);
}
这种状况非常不利。 大约1人可以建议我定期表示Xml,特别是:
<object id="ieooui" classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D">
以及
<object classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id="ieooui">
感谢一吨。