I would use a replacement dictionary - its easier to maintain and easier to understand (I think) so its easier all the way:
Boilerplate and create demo data / replace dict:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
internal class Program
{
static void Main(string[] args)
{
// c#7 inline func
string[] CreateDemoData(Dictionary<string, string> replDict)
{
// c#7 inline func
string FilText(string s) => $"Some text| that also incudes; {s} and more.";
return Enumerable
.Range(1, 5)
.Select(i => FilText(Guid.NewGuid().ToString()))
.Concat(replDict.Keys.Select(k => FilText(k)))
.OrderBy(t => Guid.NewGuid().GetHashCode())
.ToArray();
}
// replacement dict
var d = new Dictionary<string, string>
{
["e77f75b7-2373-dc11-8f13-0019bb2ca0a0"] = "e77f75b7-replaced",
["fbd0c892-2373-dc11-8f13-0019bb2ca0a0"] = "fbd0c892-replaced",
["76cd4297-1e31-dc11-95d8-0019bb2ca0a0"] = "76cd4297-replaced",
["cd42bb68-2073-dc11-8f13-0019bb2ca0a0"] = "cd42bb68-replaced",
["96b97150-cd45-e111-a3d5-00155d10010f"] = "96b97150-replaced",
};
var arr = CreateDemoData(d);
Code that creates the actual replaced array:
// c#7 inline func
string Replace(string a, Dictionary<string, string> dic)
{
foreach (var key in dic.Keys.Where(k => a.Contains(k)))
a = a.Replace(key, dic[key]);
return a;
}
// select value from dict in key in dict else leave unmodified
var b = arr.Select(a => Replace(a, d));
// if you have really that much data (20k guids of ~50byte length
// is not really much imho) you can use the same approach for in
// place replacement - just foreach over your array.
Output code:
Console.WriteLine("\nBefore:");
foreach (var s in arr)
Console.WriteLine(s);
Console.WriteLine("\nAfter:");
foreach (var s in b)
Console.WriteLine(s);
Console.ReadLine();
}
}
Output:
Before:
Some text| that also incudes; a5ceefd8-1388-47cd-b69e-55b6ddbbc133 and more.
Some text| that also incudes; 76cd4297-1e31-dc11-95d8-0019bb2ca0a0 and more.
Some text| that also incudes; 3311a8c5-015e-4260-af80-86b20b277234 and more.
Some text| that also incudes; ed10c79c-dad6-4c88-865c-4d7624945d66 and more.
Some text| that also incudes; 96b97150-cd45-e111-a3d5-00155d10010f and more.
Some text| that also incudes; 0226d9b1-c5f0-41fb-9294-bc9297e8afd9 and more.
Some text| that also incudes; e77f75b7-2373-dc11-8f13-0019bb2ca0a0 and more.
Some text| that also incudes; a04d1e34-e7bc-4bbc-ae0e-12ec846a353c and more.
Some text| that also incudes; cd42bb68-2073-dc11-8f13-0019bb2ca0a0 and more.
Some text| that also incudes; fbd0c892-2373-dc11-8f13-0019bb2ca0a0 and more.
Output:
After:
Some text| that also incudes; a5ceefd8-1388-47cd-b69e-55b6ddbbc133 and more.
Some text| that also incudes; 76cd4297-replaced and more.
Some text| that also incudes; 3311a8c5-015e-4260-af80-86b20b277234 and more.
Some text| that also incudes; ed10c79c-dad6-4c88-865c-4d7624945d66 and more.
Some text| that also incudes; 96b97150-replaced and more.
Some text| that also incudes; 0226d9b1-c5f0-41fb-9294-bc9297e8afd9 and more.
Some text| that also incudes; e77f75b7-replaced and more.
Some text| that also incudes; a04d1e34-e7bc-4bbc-ae0e-12ec846a353c and more.
Some text| that also incudes; cd42bb68-replaced and more.
Some text| that also incudes; fbd0c892-replaced and more.