Advertisement
valent1n

Homework TextFiles - Task 10

Jan 12th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4.  
  5. class ExtractFromXML
  6. {
  7.     static void Main()
  8.     {
  9.         string xmlPath = @"..\..\Test.xml";
  10.  
  11.         ExtractText(xmlPath);
  12.     }
  13.  
  14.     static void ExtractText(string path)
  15.     {
  16.         StreamReader reader = new StreamReader(path);
  17.         StringBuilder textToExtract = new StringBuilder();
  18.  
  19.         using (reader)
  20.         {
  21.             string line = reader.ReadLine();
  22.  
  23.             while (line != null)
  24.             {
  25.                 line = line.Trim();
  26.  
  27.                 for (int i = 0; i < line.Length; i++)
  28.                 {
  29.                     // append every char after '>' till char is equal to '<'
  30.                     if (line[i] == '>' && i + 1 < line.Length)
  31.                     {
  32.                         i++;
  33.  
  34.                         while (line[i] != '<')
  35.                         {
  36.                             textToExtract.Append(line[i]);
  37.                             i++;
  38.                         }
  39.  
  40.                         Console.WriteLine(textToExtract.ToString().Trim());
  41.                         textToExtract.Clear();
  42.                     }
  43.                 }
  44.  
  45.                 line = reader.ReadLine();
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement