I'm quite new to C# and had been looking for solutions regarding converting string to integer using Int32.Parse, Int32.TryParse, Convert.Int32 etc. However I couldn't find the right solutions to get near what I wanted. I had found a similar post here: Operator '>=' cannot be applied to operands of type 'string' and 'string' , but still couldn't find the right solutions.
Here's a brief of what I'm trying to code.
Open an Excel file named "compare.xls", read file and write to a text file named "tline.txt"
Then open text file "tline.txt", read text line by line and only write to a text file named "mkmatlab.txt" with conditional statements. Conditional statement: If the number read from the line is 25 <= x <= 50, write it to "mkmatlab.txt" (only write to the file if it's an integer).
An idea of the contents in the Excel file:
A1..| B1....... | C1........ | D1........| E1........|
0.1 |10.2000 |53.6000 |52.7894 |24.9608
0.2 |26.8209 |55.0851 |56.4726 |35.8431
0.3 |10.1009 |56.0314 |56.5013 |27.8922
0.4 |17.7008 |60.0054 |59.7650 |37.8018
*The symbol .. and | is just to act as spacing here, the Excel file or text file doesn't contain any of these symbols.
Explanations: First row contain A1 to E1. For Column A1 contain 0.1 to 0.4, and so on for column B1 to E1.
I have place comment on the line
if (words1[t] >= 25 && words1[t] <= 50)
where I need help with.
StreamReader fidin = File.OpenText(@"C:\Users\Student\Downloads\compare.xls");
StreamWriter tline = File.CreateText(@"C:\Users\Student\Downloads\tline.txt");
string F = fidin.ReadToEnd();
fidin.Close();
string[] words = F.Split(';');
Array.Sort(words);
for (int f = 0; f < words.Length; f++)
tline.WriteLine(words[f]);
tline.Close();
StreamReader tline1 = File.OpenText(@"C:\Users\Student\Downloads\tline.txt");
StreamWriter fidout = File.CreateText(@"C:\Users\Student\Downloads\mkmatlab.txt");
string T = tline1.ReadToEnd();
tline1.Close();
string[] words1 = T.Split(';');
Array.Sort(words1);
int counter = 0;
string line;
while ((line = tline1.ReadLine()) != null)
{
System.Console.WriteLine(line);
fidout.WriteLine(line);
counter++;
Console.ReadKey();
}