Maybe a basic question but let us say I have a string that is 2000 characters long, I need to split this string into max 512 character chunks each.
Is there a nice way,
I will dare to provide a more LINQified version of Jon's solution, based on the fact that the string
type implements IEnumerable
:
private IList SplitIntoChunks(string text, int chunkSize)
{
var chunks = new List();
int offset = 0;
while(offset < text.Length) {
chunks.Add(new string(text.Skip(offset).Take(chunkSize).ToArray()));
offset += chunkSize;
}
return chunks;
}