I am having a problem in searching a substring from a string.
StreamReader objReader = new StreamReader("D:\\C#\\Mid\\project\\real estate\\store.txt");
string sLine = "";
ArrayList arrText = new ArrayList();
Console.Write("Type the keyword you want to search : ");
string search = Console.ReadLine();
while (sLine != null)
{
sLine = objReader.ReadLine();
int x = sLine.IndexOf(search);
Console.WriteLine(x);
if (sLine != null && x != -1)
{
Console.WriteLine(x);
arrText.Add(sLine);
}
Console.WriteLine(x);
}
Console.WriteLine("Here");
objReader.Close();
foreach (string sOutput in arrText)
Console.WriteLine(sOutput);
Console.ReadLine();
The message i am getting is
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
sLine.IndexOf(search);