I have a list of string that contains few strings with some special characters like -, [, ], (, ).
I am passing a string to a method where I need to parse the above list & find if the exact match is found or not.
For this I have written the below code, but when ever the special characters are present in the string, its not able to compare.
foreach (var item in myList)
{
if (myInput.Trim().ToUpper() == item.Trim().ToUpper() ) //Here myInput is "In - Com [SP]"
{
count++;
}
}
But if I compare a static string by a preceding @ symbol, then the compare is working fine. For Example :
if (item == @"In - Com [SP]")
{
count++;
}
Can anyone please help me how to incorporate this for a dynamic list of strings? NB : We cant concatenate @ with a string variable.
Any ways exist by using Regex?