Reading a File to a String in C#, including Tabs and Newlines etc.

StreamReader sr = new StreamReader(fileName);
fileAsString= sr.ReadToEnd();
sr.Close();

This is very handy if you want to compare a string that is to be written to a file, with a file that already exists.
Used it for some unit testing.

Advertisements

One Response to “Reading a File to a String in C#, including Tabs and Newlines etc.”

  1. Lashawn Says:

    Hmm it appears like your site ate my first comment (it was extremely long)
    so I guess I’ll just sum it up what I wrote and say, I’m
    thoroughly enjoying your blog. I as well am an aspiring blog blogger but I’m still new to the whole thing. Do you have any tips and hints for novice blog writers? I’d definitely appreciate it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: