Hesham Hassanein

Hesham Hassanein

  • NA
  • 140
  • 17k

reading data from text file and returning string

Sep 22 2014 4:24 AM
Hello,
 
I have a text file that contains the following information
 
1             no mobile
2            new mobile
641       SonyEricsson_Sunny_Standard_v09
643       Nokia_6700s_Standard_v09 
 
There are no white spaces in the txt file, the first column is the Mobile ID and the second column is the Mobile Type.
 
I have wrote a small code that takes the input from the user (Mobile ID) and it should return the Mobile Type. I used Parse function
Please not that ID is int while Type is string.
Here is the small code, but i don't know whats missing to get the string which is the mobile type according to the input by the user.
Thanks for your help
 
int TestID = 0;
int MobileID = 0;
System.Console.WriteLine("Enter Test ID in Numbers and press enter (1:SMS) (2:Call a Number)");
TestID = Convert.ToInt32(Console.ReadLine());
System.Console.WriteLine("You entered the number:" + TestID + ".");
System.Console.WriteLine("Enter Mobile ID in Numbers and press enter");
MobileID = Convert.ToInt32(Console.ReadLine());
System.Console.WriteLine("You entered the number:" + MobileID + ".");
Console.ReadKey();

StreamReader reader = File.OpenText(@"C:\Robotron\Execution\MobileID_Type.txt");


string line;
while ((line = reader.ReadLine()) != null)
{
string[] fields = line.Split('\t');
int MobileType = Convert.ToInt32(fields[1]);
}


Console.ReadKey(); 
 
 
 
 

Answers (7)