How to trim html tags from text in asp.net grid view?
I have used asp.net ajax html editor and i s开发者_Python百科aved data in database. But now i want to retrieve it and show it in grid view. But when i retrieve that, it also shows those html tags (generated by asp.net ajax editor). So, i want to trim those tags and show plain text in grid view. How do i do that? Thanks
Go to you db and look, how it is saved. Maybe it is save encoded. If it is not the case, you can use some simple regex to remove all those tags.
<[^<]+?>
This shows you just plain text and removes all Tags
To stripe the html tags from text you can utilize the
RegEx.Replace("str","Pattern","replacementstring ");
method which there exist in
System.Text.RegularExpressions namespace
for example
Plain_Body = Regex.Replace(txtBody.Text, @"<[^>]*>", string.Empty);
here i am replacing the html specific characters with String.Empty
or ""
you can add additional characters if you wish to pattern like @"<[^>]*>" and spaces( ) and Ampersand(&) etc
精彩评论