【发布时间】:2009-10-16 10:41:40
【问题描述】:
我想使用 c# 从单词(纯字符串或 html)的长摘要中获取前几个单词(100 或 200)。
我的要求是显示内容长摘要的简短描述(此内容可能包含html元素)。我能够检索纯字符串,但是当它是 html 时,元素在示例之间被剪切,我得到这样的
<span style="FONT-FAMILY: Trebuchet MS">Heading</span>
</H3><span style="FONT-FAMILY: Trebuchet MS">
<font style="FONT-SIZE: 15px;
但它应该返回带有完整 html 元素的字符串。
我有一个 Yahoo UI 编辑器来从用户那里获取内容,我正在将该文本传递给下面的方法以获取简短摘要,
public static string GetFirstFewWords(string input, int numberWords)
{
if (input.Split(new char[] { ' ' },
StringSplitOptions.RemoveEmptyEntries).Length > numberWords)
{
// Number of words we still want to display.
int words = numberWords;
// Loop through entire summary.
for (int i = 0; i < input.Length; i++)
{
// Increment words on a space.
if (input[i] == ' ')
{
words--;
}
// If we have no more words to display, return the substring.
if (words == 0)
{
return input.Substring(0, i);
}
}
return string.Empty;
}
else
{
return input;
}
}
我正在尝试从用户那里获取文章内容并在列表页面上显示简短摘要。
【问题讨论】:
-
你目前正在做什么来获取单词?