using System;
public class Program
{
public static void Main()
string ids = "1234, 2584, 324234, 2345,45,435,4334,3,456,456,467,568,786,79,3,324,345,464,55,234,4565,8,65,643,637,56,56,34,67";
int nextIndex = 0;
while(ids.Length > 0)
string value = GetString(ids, 20, out nextIndex);
Console.WriteLine(value);
ids = ids.Substring(nextIndex);
}
private static string GetString(string value, int maxLength, out int nextIndex)
if(value.Length <= maxLength)
nextIndex = value.Length;
return value;
var v = value.Substring(0, maxLength);
nextIndex = v.LastIndexOf(",");
v = v.Substring(0, nextIndex);
nextIndex += 1;
return v;