Code:
using System;
using System.IO;
class TestSearch
{
public static void Main()
{
StreamReader streamReader = new StreamReader("search.txt");
string text = streamReader.ReadToEnd();
streamReader.Close();
string[] names = text.Split('\n');
if(MatchString(names, "foo")
Console.Write("match");
else
Console.Write("no match");
}
public static bool MatchString(string[] data, string value)
{
foreach (string i in data)
{
if (String.Compare(i,value)==0)
{
return true;
}
}
return false;
}
}
This code would take extract the data contained in the text file (search.txt) and place it inside an array. The search.txt file contains foo, bazz and bar. When I use the MatchString function I created I always get a "no match" even if the value I passed on to the function is inside the file. Please, I need your help mga masters!
If you have a better way of doing this please post it!