I'm trying to create a program that reads a text file and converts each line to a string array element. Each element in the array looks like this "5920 BECDBBAADCBACABEBBED". I need to be able to get rid of the 4 digits and space, and only keep the letters.
Using the code "string[0] = string[0].Substring(5);" works for individual elements, but once I put it into a for loop it throws an error.
string[] canidateAnswers = File.ReadAllLines("C:/Users/Dayton/Desktop/exam.txt");
canidateAnswers = canidateAnswers.Skip(1).ToArray();
for (int x = 0; x < canidateAnswers.Length; x++)
{
canidateAnswers[x] = canidateAnswers[x].Substring(5);
}
Console.WriteLine(canidateAnswers[0]);
Console.ReadKey();
x
when the error happens? What is the exact error message you're getting? That information is right on the screen in front of you, but we can't see it from here, so you should include it in your question so that we have it as well. – Ken White Apr 10 '19 at 0:24startindex
of 5. So the problem is that you're trying to take the substring of a line shorter than 5. The debugger can help you figure out which line was the last that worked, and the problem will be with the line after that - what's the issue with that line? – Ken White Apr 10 '19 at 0:29