Skip to main content
Post Undeleted by Steve
added 3 characters in body
Source Link
Steve
  • 216.6k
  • 22
  • 242
  • 296

This be can resolved with a simple Linq code

public static IEnumerable<string> SplitByLength(this string input, int lengthgroupSize)
{
    // First split the input to the comma.
    // this will give us an array of all single numbers
    string[] numbers = input.Split(','); 

    // Now loop over this array in groupSize blocks
    for (int index = 0; index < numbers.Length; index++index+=groupSize)
    {
        // Skip numbers from the starting position and 
        // take the following groupSize numbers, 
        // join them in a string comma separated and return 
        yield return string.Join(",", numbers.Skip(index * length).Take(lengthgroupSize));
    }
}

This be can resolved with a simple Linq code

public static IEnumerable<string> SplitByLength(this string input, int length)
{
    
    string[] numbers = input.Split(',');
    for (int index = 0; index < numbers.Length; index++)
    {
        yield return string.Join(",", numbers.Skip(index * length).Take(length));
    }
}

This be can resolved with a simple Linq code

public static IEnumerable<string> SplitByLength(this string input, int groupSize)
{
    // First split the input to the comma.
    // this will give us an array of all single numbers
    string[] numbers = input.Split(','); 

    // Now loop over this array in groupSize blocks
    for (int index = 0; index < numbers.Length; index+=groupSize)
    {
        // Skip numbers from the starting position and 
        // take the following groupSize numbers, 
        // join them in a string comma separated and return 
        yield return string.Join(",", numbers.Skip(index).Take(groupSize));
    }
}
Post Deleted by Steve
Source Link
Steve
  • 216.6k
  • 22
  • 242
  • 296

This be can resolved with a simple Linq code

public static IEnumerable<string> SplitByLength(this string input, int length)
{
    
    string[] numbers = input.Split(',');
    for (int index = 0; index < numbers.Length; index++)
    {
        yield return string.Join(",", numbers.Skip(index * length).Take(length));
    }
}