using System.Collections.Generic;
using System.Threading.Tasks;
namespace ConsoleApplication1
static void Main(string[] args)
string text1 = "The quick brown fox jumps over the lazy dog.";
string insertion1 = "<b>";
string insertion2 = "</b>";
int[][] Markers = new int[][]
string result = Insert(text1, Markers, insertion1, insertion2);
Console.WriteLine(result);
public static List<ListOfInsertPos> Converter(int[][] Markers, string text)
List<ListOfInsertPos> newMarkers = new List<ListOfInsertPos>();
for (int i = 0; i < Markers.Length; i++)
if (Markers[i][0] <= text.Length && Markers[i][0] + Markers[i][1] <= text.Length)
newMarkers.Add(new ListOfInsertPos() { Index = Markers[i][0], Whitch = 0 });
newMarkers.Add(new ListOfInsertPos() { Index = Markers[i][0] + Markers[i][1], Whitch = 1 });
List<ListOfInsertPos> SortedList = newMarkers.OrderByDescending(o => o.index).ThenByDescending(c => c.whitch).ToList();
public static string Inserter(string original, List<ListOfInsertPos> positions, string insertion1, string insertion2)
for (int i = 0; i < positions.Count; i++)
if (positions[i].whitch == 0)
original = original.Insert(positions[i].index, insertion1);
if (positions[i].whitch == 1 )
original = original.Insert(positions[i].index, insertion2);
public static string Insert(string text, int [][] Markers, string insertion1, string insertion2)
List<ListOfInsertPos> SortedMarkers = Converter(Markers,text);
return Inserter(text, SortedMarkers, insertion1, insertion2);