0
모든 HTML 및 XML을 제거해야하는 문자열이 있습니다. 저는 정규 표현식에별로 좋지 않습니다.문자열에서 xml 및 html을 제거하십시오.
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 and 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);
}
HTML을 위해 나는 정말 유용한 코드를 발견했다.
<object id="ieooui" classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D">
및
<object classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id="ieooui">
감사 톤 : some1 특히위한뿐만 아니라 나에게 XML에 대한 정규 표현식을 제안 해주십시오 수 있습니다.
처럼 (당신은 어떤 언어 (들 표시해야합니다) 사용중인) –
당신이'Regex.Replace (미리보기, "<.*?>가", "") '않는 이유를 말할 수 태그를 코드를 포맷하고 해결하십시오 귀하의 의견으로는 * XML을 위해 * 작동하지 않습니까? – Tomalak