Handle string
-
How can i do to replace Html Tag For example in my project when i input <br> or <p> the error message will display Could you can write an function in C# to replace the HTML Tag Thanks for helping. I tried so hard and got so far
-
How can i do to replace Html Tag For example in my project when i input <br> or <p> the error message will display Could you can write an function in C# to replace the HTML Tag Thanks for helping. I tried so hard and got so far
-
How can i do to replace Html Tag For example in my project when i input <br> or <p> the error message will display Could you can write an function in C# to replace the HTML Tag Thanks for helping. I tried so hard and got so far
If you need an HTML-Encoded string you can use the System.Web.HttpUtility.HtmlEncode function. You must reference the System.Web assembly to use this function. If you need to actually strip the Html tags you coud use a regular expression like this:
// replace br an p tags with linefeed string cleanedText = System.Text.RegularExpressions.Regex.Replace(htmlString,@"(?:]*>)","\r\n"); // remove tags cleanedText = System.Text.RegularExpressions.Regex.Replace(cleanedText,@"(?:<[/!]?([A-Z][A-Z0-9]*)[^>]*>)","");
This code is very basic. It will not strip scripts nor will it handle tables pretty well. I hope this is at least a start for you.