【发布时间】:2011-01-05 23:14:42
【问题描述】:
我有一个显示新闻文章的 ASP.NET MVC 应用程序,对于主要段落,我有一个截断和 HTML 标记剥离器。例如<p><%= item.story.RemoveHTMLTags().Truncate() %></p>
这两个函数来自一个扩展,如下:
public static string RemoveHTMLTags(this string text)
{
return Regex.Replace(text, @"<(.|\n)*?>", string.Empty);
}
public static string Truncate(this string text)
{
return text.Substring(0, 200) + "...";
}
但是,当我创建一篇新文章说一个只有 3-4 个单词的故事时,它会抛出这个错误:Index and length must refer to a location within the string.
Parameter name: length
有什么问题?谢谢
【问题讨论】:
-
在 164 次观看中,我不是唯一一个发现这个话题有用并因此投票赞成的人
标签: asp.net-mvc