Perhaps this can be used to handle extremely extreme files:
public IEnumerable<string> GetChunks(this string sourceString, int chunkLength) { using(var sr = new StringReader(sourceString)) { var buffer = new char[chunkLength]; int read; while((read= sr.Read(buffer, 0, chunkLength)) == chunkLength) { yield return new string(buffer, 0, read); } } }
Actually, this works for any TextReader
. StreamReader
is the most commonly used TextReader
. You can process very large text files (IIS log files, SharePoint log files, etc.) without downloading the entire file, but reading it line by line.
source share