I have many patterns that want to find matched string in many string arrays and replace them with \"NON\" string. for example, if we have:
str[0]={\"this\",\"is\
If you want a mutating solution:
public void ReplaceStrs(string[] srcStrs, string[] patterns, string changeTo)
{
for (int i=0; i < srcStrs; i++) {
if (Array.IndexOf(patterns, toChange[i]) >= 0) {
srcStrs[i] = changeTo;
}
}
}
Non-mutating:
public string[] ReplaceStrs(string[] srcStrs, string[] patterns, string changeTo) {
srcStrs.Select(s => Array.IndexOf(patterns, s) >= 0 ? changeTo : s).ToArray();
}
A one liner just for fun :]
str = Array.ConvertAll(str, a => Array.ConvertAll(a, i => patterns.Contains(i) ? "NON" : i));