-2

I created a regex pattern to find some string in a text file. I need to know the string position when regex pattern is match.

But I must use ReadToEnd()to read the text file, and then use MatchCollection to collect all result, so does anyone know if have any method can get string position in the text file.

Henry Hsu
  • 1
  • 3

1 Answers1

1

have you even searched for this prior to asking your question? Doesn't it also work with readLine like shown here?

Community
  • 1
  • 1
XikiryoX
  • 1,898
  • 1
  • 12
  • 33
  • I've searched, and I know how to record line number when I use "ReadLine()" function, but I want to find out how to record line number when I used "ReadToEnd()" function via streamreader to read all content. – Henry Hsu Dec 03 '14 at 14:28
  • In the link they use ReadLine() and put that in a loop untill the line is null - -If I'm no mistaking that will actually do the same as ReadToEnd(). Is there any reason why this would not work in your case? - you can use a list to store the index of the line everytime you find an occurence of your pattern inside your loop. – XikiryoX Dec 04 '14 at 09:32