How to replace a character in string using LINQ
.net, c#, linq, string
Solution
For your interviewer
string output = new String(input.Select(ch => ch == '2' ? '0' : ch).ToArray());
I think intend was to see if you understand that string could be treated as sequence of characters. Interviews often have questions not related to real-life programming. I personally hate questions about inheritance tree with `new` modifiers.
Problem
for example:- replace 2 with 0 for the following input Input: string strInput = "21212121"; Output: "01010101" How to do it with LINQ. Note: dataType is string.