0

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 exist in txt Field , but without any codes like <...> , just a pure text !! how can I do this !?

Rawhi
  • 6,155
  • 8
  • 36
  • 57

3 Answers3

3

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

wp78de
  • 18,207
  • 7
  • 43
  • 71
James Gaunt
  • 14,631
  • 2
  • 39
  • 57
1
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();
}
Rawhi
  • 6,155
  • 8
  • 36
  • 57
0

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;
WraithNath
  • 17,658
  • 10
  • 55
  • 82