Split String By Length - CSharp System

CSharp examples for System:String Split

Description

Split String By Length

Demo Code


using System.Collections.Generic;
using System;/*w  ww  .  j  a  v a2  s  . co  m*/

public class Main{
        private static List<string> SplitStringByLength(string str, int chunkSize)
        {
            List<string> list = new List<string>();
            int i;
            for (i = 0; i < str.Length / chunkSize; i++)
            {
                list.Add(str.Substring(i * chunkSize, chunkSize));
            }
            i = i * chunkSize;
            if (i < str.Length - 1)
                list.Add(str.Substring(i, str.Length - i));
            return list;
        }
}

Related Tutorials