How to update a string by LINQ when condition matched

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
i tried this code but did not compile

char[] array1 = { '+', '-', '*','/','%' };
string formula2 = "Consensus Model~Total Operating Expenses-GAAP~CL~4Q 2014 + Consensus Model~Total Operating Expenses-GAAP~CL~3Q 2014 - Consensus Model~Total Operating Expenses-GAAP~CL~2Q 2014 / Consensus Model~Total Operating Expenses-GAAP~CL~1Q 2014";

foreach (var foundchar in formula2.Where(w => array1.Where(z=> z.ToString()==w.ToString()).ToList()))
{
foundchar = "#";
}


basically i want to search formula2 string variable and if any char in formula2 match with a char in char array then it will be replaced by #.

but my code is not compiling. so all operator will be replaced by # for right output. thanks

Continue reading...
 
Back
Top