I am working on text file..i want to know how to search for a string in text file and then perform the operations on that string.I have written a code but there is some problem with "if condition",when the particular string comes,the control skips to the next line..it doesnot perform any operation on that string.. Below is the line from text file from which i am trying to find "MerchantNo:105838015" and then performing Substring operation on it to get only the number..There is a space in between the line.. MERCHANTNO:105838015 AGENT CODE 00913
And this is the code:
StreamReader sr = new StreamReader(fldr);
string line = null;
while ((line = sr.ReadLine()) != null)
{
str = line.Trim().Split(' ');
for (int i = 0; i < str.Length; i++)
{
if (str.ToString().ToUpper().Contains("MERCHANTNO:105838015"))
{
//str = line.Split(' ');
string MNo1 = line.Substring(15, 23);
MNo = Convert.ToInt32(MNo1.ToString());
}
break;
}
//MessageBox.Show("Line is:" +line);
}
MessageBox.Show("MerchantNo is:" +MNo);
Please do say me what i have to do??