Yas*_*ser 6 razor asp.net-mvc-3
我正在使用MVC 3和Razor View引擎.
我想做什么
我正在使用MVC 3制作博客,我想删除所有HTML格式标签<p> <b> <i>等.
我正在使用以下代码.(确实有效)
@{
post.PostContent = post.PostContent.Replace("<p>", " ");
post.PostContent = post.PostContent.Replace("</p>", " ");
post.PostContent = post.PostContent.Replace("<b>", " ");
post.PostContent = post.PostContent.Replace("</b>", " ");
post.PostContent = post.PostContent.Replace("<i>", " ");
post.PostContent = post.PostContent.Replace("</i>", " ");
}
Run Code Online (Sandbox Code Playgroud)
我觉得必须有一个更好的方法来做到这一点.任何人都可以指导我这个.
Yas*_*ser 22
这是我现在使用的..
post.PostContent = Regex.Replace(post.PostContent, @"<[^>]*>", String.Empty);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16435 次 |
| 最近记录: |