All pastes #439769 Raw Edit

CP:Simon

public text v1 · immutable
·published 2007-04-14 14:52 UTC
rendered paste body
/*
  IsInFile:
  Compile to IsInFile.exe and type "IsInFile <FILENAME> <STRING>" (Minus the quotes) into command line.
  		  Example: IsInFile Bob.txt Hello
*/

using System;
using System.IO;

public class IsInFile {
	public static void Main(String[] args) {
		try {
			using(StreamReader fi = new StreamReader(args[0])) {
				String line;
				bool IsFound=false;
				while ((line = fi.ReadLine()) != null) {
					if (line.Contains(args[1])) {
						Console.WriteLine(line);
						IsFound = true;
					}
				}
				if (!IsFound) {
					Console.WriteLine("Could not find " + args[1] + " in " + args[0] + '.');
				}
			}
		}
		catch (Exception e)
		{
			Console.WriteLine("The file could not be read:");
			Console.WriteLine(e.Message);
		}
	}
}