I have a string and need to replace some content based on certain substrings appearing in the string. e.g. a sample string might be
(it.FirstField = "fred" AND it.SecondField = True AND it.ThirdField = False AND it.FifthField = True)
and I want to transform it to:
(it.FirstField = "fred" AND it.SecondField = 'Y' AND it.ThirdField = 'N' AND it.FifthField = True)
i.e. if the substring appears in the string, I want to change the True to 'Y' and the False to 'N', but leave any other True/False values intact.
I have an array of substrings to look for:
string[] booleanFields = { "SecondField", "ThirdField", "FourthField" };
I can use something like if (booleanFields.Any(s => inputString.Contains(s)))
to find out if the string contains any of the keywords, but what's the best way to perform the replacement?
Thanks.