svetlozar_kirkov

Leave plain text from HTML (Exercise)

Oct 11th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace ConsoleTests
  7. {
  8.     class ConsoleTests
  9.     {
  10.         static void Main()
  11.         {
  12.             List<string> list = new List<string>();
  13.             using (StreamReader reader = new StreamReader("file.txt"))
  14.             {
  15.                 string line;
  16.                 while ((line = reader.ReadLine()) != null)
  17.                 {
  18.                     list.Add(line);
  19.                 }
  20.             }
  21.  
  22.             foreach (var stuff in list)
  23.             {
  24.                 string temp = ExtractHtmlInnerText(stuff);
  25.                 if (temp.Length!=0)
  26.                 {
  27.                     Console.WriteLine(temp);
  28.                 }
  29.             }
  30.  
  31.         }
  32.         public static string ExtractHtmlInnerText(string htmlText)
  33.         {
  34.             Regex regex = new Regex("(<.*?>\\s*)+", RegexOptions.Singleline);
  35.  
  36.             string resultText = regex.Replace(htmlText, " ").Trim();
  37.  
  38.             return resultText;
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment