I have a string like this in C#:
string a = "A|B|C|D"
I want to split this string on the pipe character and prepend some text to each entry. Currently, I am doing a split like this:
string[] result = a.Split('|')
But because the string array is of a fixed size, I need to create a new array and copy the prepended result using a for loop. Is there a Linq way or a one-liner to achieve this instead of writing a for loop? In Python, I would have done a one-liner for loop:
newresult = ["Prepend string " + x for x in result]
Any suggestions?
I found this to be easy enough, if you say want to join it back too:
string.Join(" , ", devices.Select(s => "PREFIX = " + s).ToArray());