C# .NET - Replace Strings Of string builder using regex

Asked By Dilip Sharma on 13-Dec-12 08:09 AM
Hi ,

Can any one please suggest what can be regex for  this data
 i have string builder which contains following data from text file ..
Now i want to replace  from <a:begin>   to     <b:/end>  by blank space in C# using regex , 



A B C D My use full data data 
<a:begin>
Addd as ss
1 My name is


2323
33
text 
<b:/end>
Other Useful Data 

Thanks 
Robbe Morris replied to Dilip Sharma on 13-Dec-12 08:25 AM
 I tweaked an existing function I had for stripping html out of text.  There is probably a way to avoid the replace of the a:being and b:end tags.  In fact, it might even work without doing the replace.  This should give you a good start.

 public static string StripHtml(string html)
 {
    if (String.IsNullOrEmpty(html)) return string.Empty;
    html = html.Replace("<a:begin>", "<begin>").Replace("<b:end>","<end>");
    return Regex.Replace(html, @"<[^>]+>", " ", RegexOptions.IgnoreCase).Trim();
 }
Dilip Sharma replied to Dilip Sharma on 13-Dec-12 11:58 AM
Hi i have small issue


my file is 


A B C D unuse data 
<begin>
Addd as ss
1 My name is




2323
33
text 
</end>
34344
no need


and my code is
StringBuilder mSb = new StringBuilder();
           StreamReader sr = new StreamReader(@"E:\check.txt");
           String line;
 
           while (sr.ReadLine() != null)
           {
               
               mSb.AppendLine(sr.ReadLine());
                
           }
string matc = new Regex(@"(<begin>)(\n?.*)*</end>)?").Match(mSb.ToString()).ToString();


here it reading all file , but i just want till </end>
if i am removing ?   from end , my program is crashing ..


Thanks