I need to retrieve the last character of a file. It may be a line break, or one of many special characters. Can I retrieve this character without parsing through the entire file? Or is t开发者_高级运维here a way that I can read an entire file into a string without worry about line breaks?
I will essentially need to split the contents of the file, based on the last character of the file. So if it is a line break, I will split the string by '\n'.
You can Seek() to the end of file - 1, then just Read() one byte.
I do not have the exact functionnames and constants for the Seek at the moment, check the Stream Documentation for those.
string s = File.ReadAllText("test.txt");
string[] split = s.Split(s[s.Length - 1]);
StreamReader has the ReadToEnd() method. It reads the complete file into a string.
精彩评论