Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I have a string
<div dir="ltr">Test Mail 1 Body<br></div>


and now i want to remove only
<div dir="ltr">


Output should be
Test Mail 1 Body


Unable to remove, can anybody please help me?

What I have tried:

string str = body.Replace("<div dir="ltr>"", " ");


I am getting error that ltr name does not exist in current context.
Posted
Updated 14-Mar-17 18:51pm

1 solution

string inputText = "<div dir=\"ltr\">Test Mail 1 Body<br></div>";
       string pattern = "<div dir=\"ltr\">(.*)</div>";
       Regex regex = new Regex(pattern);
       var matches = regex.Match(inputText);
       string text = matches.Groups[1].ToString();
       text = text.Replace("<br>", "");
 
Share this answer
 
v2
Comments
Adityakumar2318 15-Mar-17 1:07am    
Thank you so much sir. You saved my day.
Karthik_Mahalingam 15-Mar-17 1:12am    
Welcome :)
Bryian Tan 15-Mar-17 1:45am    
just curious, what if the body content look like
before ltr <div dir=\"ltr\">Test Mail 1 Body<br></div> after ltr <div>div without ltr</div> after div 
Karthik_Mahalingam 15-Mar-17 1:57am    
then will have to reconsider the pattern :)
Bryian Tan 15-Mar-17 2:04am    
Nice stuff by the way. +5 :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900