我在我的数据库中有新闻表,其中包括=> Id,标题,文本。
我需要能够从txt字段中存在的整个文本中获得描述文本,但没有像<...>这样的任何代码,只是一个纯文本!!我怎么能这样做呢!?
发布于 2011-02-28 19:57:07
public static string Strip(string source)
{
char[] array = new char[source.Length];
int arrayIndex = 0;
bool inside = false;
for (int i = 0; i < source.Length; i++)
{
char let = source[i];
if (let == '<')
{
inside = true;
continue;
}
if (let == '>')
{
inside = false;
continue;
}
if (!inside)
{
array[arrayIndex] = let;
arrayIndex++;
}
}
string text = new string(array, 0, arrayIndex);
return System.Text.RegularExpressions.Regex.Replace(text, @"\s+", " ").Trim();
}发布于 2011-02-28 17:51:30
通过使用HTML Agility Pack
http://htmlagilitypack.codeplex.com/
来提取HTML中的所有文本节点。
这个问题解释了如何做到这一点:
发布于 2011-02-28 17:50:55
你能不能像这样:
(首先获取记录,然后添加一个属性以返回一些文本)
return Text.Length >= 100 ? Text.SubString(0,100) : Text;https://stackoverflow.com/questions/5140376
复制相似问题