ReadAllText and reading a textfile into a string

Frans_Truyens
Frans_Truyens used Ask the Experts™
on
I want to read a textfile into a string. The problem is that I need a CrLf character at the end of each line.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
It is supposed to be already there if it is in your source file.

Author

Commented:
I read a large file, >150 Mega, with ReadAllText. This file is a .txt file, with linebreaks. Then  I am using Regex to find the lines that start with STOP. There are multiple lines that start with STOP. But it will only find the first one. It is not an error of Regex, but just, the result is only one line.

Author

Commented:
I know I can use a StreamReader, but that is rather slow. I want ReadAllText, but that it keeps the linebreakw. StreamReader is just too slow;
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Senior .Net Consultant
Top Expert 2016
Commented:
Any reason to load such a big file all at once?

Have you tried your regex on a much smaller file? Might be a buffer overrun with the regex.

Author

Commented:
I am searching those files.

Author

Commented:
It has to do with the end of line characters. Or I presume that that is the problem. Because if I look for a string inside the file, on any position, it works. Only if I am looking for leading strings, I have that problem

Author

Commented:
I found it myself. It is required to use the option 'multiline', and then it works. Thanks for your time.
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
On which object that multiline option?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial