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
  • 5,735
  • 7
  • 33
  • 56

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
  • 17,272
  • 6
  • 36
  • 68
James Gaunt
  • 14,443
  • 2
  • 38
  • 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
  • 5,735
  • 7
  • 33
  • 56
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,078
  • 9
  • 52
  • 80