The text file you are reading has blank lines (Error.txt).
When the current line is a blank line, its length is 0, then use IndexOf(Char, Int32), startIndex is greater than the length of the string, this problem will occur.
Try to add a judgment, if the current line length is 0, use continue to enter the next round of loop.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.