making a description text !
I have in my database the News Table which consist of => Id, Title, txt .
I need to be able to get a description text from the whole text which exis开发者_如何学Ct in txt Field , but without any codes like <...> , just a pure text !! how can I do this !?By using the HTML Agility Pack:
http://htmlagilitypack.codeplex.com/
To extract all the text nodes in the HTML.
This question explains how you would do that:
C#: HtmlAgilityPack extract inner text
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();
}
Can you so something like:
(Get the record first then add a property to return some of the text)
return Text.Length >= 100 ? Text.SubString(0,100) : Text;
精彩评论