Insert Separator Every Count - CSharp System

CSharp examples for System:String Split

Description

Insert Separator Every Count

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System.Collections.Generic;
using System;// ww w  .j a  va2  s.c  om

public class Main{
        public static string InsertSeparatorEvery(string input, string separator, int count)
        {
            string ret = "";
            for (int i = 0; i < input.Length; i++)
            {
                if (i + count < input.Length)
                    ret += input.Substring(i, count);
                else
                    ret += input.Substring(i);

                if (i != input.Length - 1)
                    ret += separator;
            }
            return ret;
        }
}

Related Tutorials