0

I have the following collection

var collection = new []
{ 
   "First1",
   "Second2",
   "Third12"
}

Then I have a lookup table, which contains keys that needs to be replaced:

var keys = new []
{ 
   Tuple.Create(1, "ABC"),
   Tuple.Create(2, "DEF")
}

The final result should be the original list with the values replaced from the lookup table

var collection = new []
{ 
   "FirstABC",
   "SecondDEF",
   "ThirdABCDEF"
}

I was trying with the aggregate function in the following way:

    string[] collection = new[]{"First#", "Second@"};

    Console.WriteLine("Before {0}", String.Join(" - ", collection));

    var keys = new[]{Tuple.Create("#", "ABC"),Tuple.Create("@", "CDE")};
    foreach ( var item in collection)
    {
        if() // my item is in any occurrence of the keys array
    }

    Console.WriteLine("After {0}", String.Join(" - ", collection));

1 Answer 1

2
for (var i = 0; i < collection.Length; i++)
{
    foreach (var k in keys)
    {
        collection[i] = collection[i].Replace(k.Item1, k.Item2);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.