c# - Get the first few words from a long summary(plain string or HTML) -


I want to get some words (100 or 200) before a long summary of words (plain string or html) #.

I need to show a brief description of the long summary of content (this content may contain html elements). I am able to retrieve the plain string, but when it is html, the element It is cut in the middle of the example, I get it like this

   & Lt; Span style = "fun-family: trebchett ms" & gt; & Lt; Font style = "font-size: 15px;  

But this string should be returned with a full HTML element.

I have a Yahoo UI editor from the user Content, and I'm going through that text below to get the summarized summary,

  public stable string GetFirstFewWords (string input, int number) {if (input.split (new four) [] {'}}, String split options, ricquiptyentry. Lang & gt; number of words) {// We still display Do not want the number of words, the int words = numberwords; // Loop through the whole essence. (Int i = 0; i & lt; input.Length; i ++) {// Increase the word on a space. Input [i] == '') {words--;} // If we do not have more words to display, return the sub-return (word == 0) {return input. Shuttle (0, I);}} return string.free;} and {return input;}}  

I get brief content from the user to get the contents of the article and the summary page on the list page Publishing'm trying to do.

Have you thought about bidding?

Although not correct, this is an idea that will get you later (more or less):

, 'Max' word does not get less than string. GetSmari (String HTML, Int Max) {string summaryHTML = string.Empty; // Load our HTML document HtmlDocument htmldoc = new HtmlDocument (); HtmlDoc.LoadHtml (HTML); Int wordCount = 0; Foreach (var element in html.doc.DocumentNode.ChildNodes) {// Internal text will skip all HTML, and give us plain text string element = element.InnerText; // We divide by space to get all the words in this element string [] elementWords = elementText.Split (new four [] {''}); // And if we have not used a lot of words ... if (the word count is & lt; = max) {// adds * external * html (which will be the appropriate // html format for this section) Summary HTML + = Element.OuterHtml; WordCount + = elementWords.Count () + 1; } And {break} }} Return Summary HTML; }

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -