Advertisement
vlad0

Text files 10

Jan 24th, 2013
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace _10.ExtractXML
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string firstFileName = "../../mytemp01.txt";//the dir of the .cs file
  15.  
  16.             ReadFile(firstFileName);
  17.         }
  18.  
  19.         private static void ReadFile(string firstFileName)
  20.         {
  21.             using (StreamReader sourceFile = new StreamReader(firstFileName))
  22.             {
  23.                 string line = sourceFile.ReadLine();
  24.                 while (line != null)
  25.                 {
  26.                     string pattern = ">[^<]*</";
  27.                     string edited;
  28.                     int length;
  29.                     foreach (Match match in Regex.Matches(line, pattern))
  30.                     {
  31.                         edited = match.Value.ToString();
  32.                         length = edited.Length;
  33.                         edited = edited.Remove(length - 2, 2); //remove </
  34.                         edited = edited.Remove(0, 1); //remove >
  35.                         if (edited != null)
  36.                         {
  37.                             Console.WriteLine(edited);
  38.                         }
  39.  
  40.                     }
  41.  
  42.                     line = sourceFile.ReadLine();
  43.                 }
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement