Advertisement
Krissy

ExtractText

Jan 28th, 2013
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. class ExtractTextFromHtml
  7. {
  8.     static void Main()
  9.     {
  10.         string text=@"<html><head><title>News</title></head><body><p><a href=""http://academy.telerik.com"">Telerik Academy</a>aims to provide free real-world practical training for young people who want to turn into skillful .NET software engineers.</p></body></html>";
  11.         int countOfOpenedTags = 0;
  12.         bool hasPrinted = false;
  13.         for (int i = 0; i < text.Length; i++)
  14.         {
  15.             if (text[i]=='<')
  16.             {
  17.                 countOfOpenedTags++;
  18.                
  19.                 if (hasPrinted==true)
  20.                 {
  21.                     Console.Write(' ');
  22.                     hasPrinted = false;
  23.                 }
  24.                 continue;
  25.             }
  26.             if (text[i]=='>')
  27.             {
  28.                 countOfOpenedTags--;
  29.                 continue;
  30.             }
  31.             if (countOfOpenedTags==0)
  32.             {
  33.                 Console.Write(text[i]);
  34.                 hasPrinted = true;
  35.             }
  36.         }
  37.         Console.WriteLine();
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement