Remove Certain Text from Xmlhttp://forums.asp.net/t/1756831.aspx/1?Remove+Certain+Text+from+XmlFri, 13 Jan 2012 01:07:43 -050017568314769887http://forums.asp.net/p/1756831/4769887.aspx/1?Remove+Certain+Text+from+XmlRemove Certain Text from Xml <p>i have Some Xml stored which is been generated from another Source</p> <p>the xml contains certain unwanted text which i need to remove them</p> <pre class="prettyprint">&lt;IceCream=&quot;Vanilla&quot;/&gt; &lt;assignedPerson&gt; -1- &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; Need to Remove this text while Reading Xml &lt;name&gt; &lt;prefix&gt;Mr..&lt;/prefix&gt; &lt;name1&gt;Martin&lt;/name1&gt; &lt;/name&gt; &lt;/assignedPerson&gt;</pre> 2012-01-07T04:49:48-05:004769929http://forums.asp.net/p/1756831/4769929.aspx/1?Re+Remove+Certain+Text+from+XmlRe: Remove Certain Text from Xml <p>You can remove it by using REGEX class of c#</p> 2012-01-07T05:37:52-05:004769959http://forums.asp.net/p/1756831/4769959.aspx/1?Re+Remove+Certain+Text+from+XmlRe: Remove Certain Text from Xml <p>i tried this but it's not working</p> <pre class="prettyprint">//Regex rgx = new Regex(@&quot;-[0-9]-&quot;); //string Xml = rgx.Replace(value, string.Empty);</pre> 2012-01-07T06:14:13-05:004769993http://forums.asp.net/p/1756831/4769993.aspx/1?Re+Remove+Certain+Text+from+XmlRe: Remove Certain Text from Xml <p>HI IF YOUR XML FILE IS ALWAYS SAME</p> <p>try this,</p> <pre class="prettyprint">var xm1=&quot;your xml code&quot;;//</pre> <pre class="prettyprint"> var str = xm1.Split('\n').Where(a =&gt; a.StartsWith("&lt;")).Select(a=&gt;a.Replace('\r',' ').Trim()); var res=String.Join("", str);</pre> <p></p> 2012-01-07T06:42:16-05:004770018http://forums.asp.net/p/1756831/4770018.aspx/1?Re+Remove+Certain+Text+from+XmlRe: Remove Certain Text from Xml <p>Made New Method and it Worked</p> <p></p> <pre class="prettyprint">public string RemoveUnWantedCharsfromXml(string XmlFile) { string Xml = string.Empty; Regex regex = new Regex(@&quot;-[0-9]&#43;-&quot;, RegexOptions.IgnoreCase); if (regex.IsMatch(XmlFile)) Xml = regex.Replace(XmlFile, String.Empty); return Xml; } san i couldn;t use method bcuz it kept giving me error in String.Join The best overload method is string[]</pre> 2012-01-07T07:10:29-05:004771575http://forums.asp.net/p/1756831/4771575.aspx/1?Re+Remove+Certain+Text+from+XmlRe: Remove Certain Text from Xml <p></p> <blockquote><span class="icon-blockquote"></span> <h4>tan_vision_12_2010</h4> the xml contains certain unwanted text which i need to remove them</blockquote> <p></p> <p>Hello</p> <p>First I'd to say that I've tested your codesit works great</p> <pre class="prettyprint">namespace A { class Program { public static string RemoveUnWantedCharsfromXml(string XmlFile) { string Xml = string.Empty; Regex regex = new Regex(@&quot;-[0-9]&#43;-&quot;, RegexOptions.IgnoreCase); if (regex.IsMatch(XmlFile)) Xml = regex.Replace(XmlFile, String.Empty); return Xml; } static void Main(string[] args) { string s = &quot;&lt;IceCream=\&quot;Vanilla\&quot;/&gt;&lt;assignedPerson&gt;-1-&lt;name&gt;&lt;prefix&gt;Mr..&lt;/prefix&gt;&lt;name1&gt;Martin&lt;/name1&gt;&lt;/name&gt;&lt;/assignedPerson&gt;&quot;; s = RemoveUnWantedCharsfromXml(s); Console.WriteLine(s); } } }</pre> <p>If you are sure that you only want to remove "-1"&mdash;&mdash;Just use this following</p> <pre class="prettyprint">string s = "Your xml contents"; s=s.Replace("-1-","");</pre> 2012-01-09T00:17:29-05:004780230http://forums.asp.net/p/1756831/4780230.aspx/1?Re+Remove+Certain+Text+from+XmlRe: Remove Certain Text from Xml <p>Hello</p> <pre class="prettyprint">var res=String.Join(&quot;&quot;,<strong> str.ToArray()</strong>);</pre> 2012-01-13T01:07:43-05:00