I want to read a file, at a specific location/line (which will always remain the same) and convert it to a string. For ex: read line 3 (which will contain numbers -3,-2, 2, 4, 7, 10 OR 12) and convert it to F,D,C,B,B-,A, OR A+. Probably I will use an if statement to tell the app which number should convert to which letter, so you can skip this part. To specify, I know how to read a file, but I need to know how to read at that specific location and convert it right away and print it.
Asked
Active
Viewed 71 times
0
-
The only way to read a specific line out of a text file is to start from the beginning and count until you reach the one you want. If your file doesn't change you can of course save the line offsets in a table for future use. – 500 - Internal Server Error Oct 03 '18 at 18:34
1 Answers
0
For reading the file at specific position look at here.
For converting to string you can do this:
Dictionary<string, string> matches = new Dictionary<string, string>()
{
{"-3", "F"}, {"-2", "D"}, {"2", "C"}, {"4", "B"}, ...
};
now conversion would be like:
string result = "notfound";
result = matches.TryGetValue(valueYouHaveRead, out result);

Ashkan Mobayen Khiabani
- 33,575
- 33
- 102
- 171