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,
using Jon's implementation and the yield keyword.
IEnumerable Chunks(string text, int chunkSize) { for (int offset = 0; offset < text.Length; offset += chunkSize) { int size = Math.Min(chunkSize, text.Length - offset); yield return text.Substring(offset, size); } }