Thursday, September 25, 2014

HyperLinks in text file C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace HyperLinksFilter
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                StreamReader sfilecontent1 = new StreamReader(@"D:\log");
                StreamWriter dfilecontent2 = new StreamWriter(@"D:\test.txt");
                string line;
                while ((line = sfilecontent1.ReadLine()) != null)
                {
                    //string[] words = line.Split(',');
                    //string k = words[1];
                    //dfilecontent2.Write(k.Trim() + "\r\n");

                    if (line.Contains("http"))
                    {
                        dfilecontent2.Write(line+"\r\n"+"\r\n");
                    }
                }
                sfilecontent1.Close();
                dfilecontent2.Close();
                Console.WriteLine("File created Successfully!");
            }
            catch (Exception ex1)
            {
                Console.WriteLine(ex1.Message);
            }
        }
    }
}