Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Hey guys I thought for a long time and finally I have code for my problem, i am posting it here so that other can get benefit from this ....</p> <pre><code> public static string RemoveIncompleteTags(string source, string tag) { source = source.Replace(" ", " "); source = source.Replace("/n", string.Empty).Replace("/r", string.Empty).Replace("/t", string.Empty); source = source.Replace("&lt;" + tag + "&gt;&lt;/" + tag + "&gt;", string.Empty); source = source.Replace("&lt;" + tag + "&gt; &lt;/" + tag + "&gt;", string.Empty); source = source.Replace("&lt;" + tag + "&gt; &lt;/" + tag + "&gt;", string.Empty); Dictionary&lt;int, string&gt; oDict = new Dictionary&lt;int, string&gt;(); string[] souceList; Dictionary&lt;int, string&gt; final = new Dictionary&lt;int, string&gt;(); bool opening = false; bool operate = false; source = source.Replace(" ", " "); source = source.Replace("&gt;", "&gt; ").Replace("&lt;", " &lt;"); source = source.Replace(" &gt;", "&gt;").Replace("&lt; ", "&lt;"); source = source.Replace(" ", " ").Replace(" ", " "); souceList = source.Split(' '); for (int i = 0; i &lt; souceList.Length; i++) { string word = souceList[i]; if (word.ToLower() == "&lt;" + tag.ToLower() + "&gt;") { opening = true; operate = true; } else if (word.ToLower() == "&lt;/" + tag.ToLower() + "&gt;") { opening = false; operate = true; } if (operate) { if (opening) { oDict.Add(i, word); final.Add(i, word); } else { if (oDict.Count != 0) { oDict.Remove(oDict.Last().Key);//.ToList().RemoveAt(oDict.Count - 1); final.Add(i, word); } else { // need not to add to the output string // code if you want to log } } operate = false; opening = false; } else { final.Add(i, word); } } if (final.Count &gt; 0) { if (oDict.Count &gt; 0) { foreach (var key in oDict.Keys) { final.Remove(key); } } StringBuilder fText = new StringBuilder(); final.ToList().ForEach(wd =&gt; { if (wd.Value.Trim().Length &gt; 0) fText.Append(wd.Value.Trim() + " "); }); return fText.ToString().Trim(); } else { return string.Empty; } } </code></pre> <p>thanks...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload