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
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();
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();
VulpesPosted Sep 25, 2014, 8:22 AM
Hesham HassaneinPosted Sep 25, 2014, 6:41 AM
VulpesPosted Sep 25, 2014, 6:01 AM
You could do it by inserting this line before you attempt to parse the first field to an int:
if (fields[0] == "MobileId") continue;
Hesham HassaneinPosted Sep 25, 2014, 5:47 AM
VulpesPosted Sep 25, 2014, 5:42 AM
So if you now use the following it should work:
string[] fields = line2.Split(';');
Hesham HassaneinPosted Sep 25, 2014, 5:24 AM
I have a csv file that i need to read. It is the same Idea as the text file of before. But
It consists of 5 columns so I am not sure if split function will be a good idea to get the element that I am searching for. I wrote the following code to get the MenuName for a specific ID.
My problem is that it always read the element as a null and it does not return what is inside.
First take alook of a part of the csv file the the code after that
This is the CSV file
MobileId;MenuTreeView;MenuName;MenuInfo;MenuAction
747;SL_Menubaum;Desktop;0;Wait
747;SL_Menubaum;Wait;0;Wait
The code;
static void Menu_Tree(int MobileID) {
StreamReader reader = File.OpenText(@"C:\Robotron\Execution\MenuTree.csv");
string line2;
string MenuName = null;
string MenuInfo = null;
while ((line2 = reader.ReadLine()) != null)
{
string[] fields = line2.Split('\t');
if (fields.Length != 5) continue;
int id = Convert.ToInt32(fields[0]);
if (id == MobileID)
{
MenuName = fields[2];
MenuInfo = fields[3];
break;
}
}
reader.Close();
if (MenuName != null)
Console.WriteLine("The Corresponding Endknot is " + MenuName + "The Corresponding MenuInfo"+ MenuInfo);
else
Console.WriteLine("There is no corresponding MenuName Information");
Console.ReadKey();
}
Do you have an idea how can i get the correct MenuName when i enter the ID. Thank you so much
VulpesPosted Sep 22, 2014, 5:12 AM