This is apparently a common question for C # users, and after researching and several attempts that I cannot use for life, I remove a couple of brackets from the string. I have a problem with Service (additional).
After doing my research, I understand that parentheses are handled differently in Regex.Replace. My research also came up with several answers that I tried, but nothing seemed to work. Here are some ways I tried to remove these brackets.
cleanValue = Regex.Replace(intVal, " ", "").Replace("(", "").Replace(")", "").Replace(",", "").Replace("/", "").Replace("-", "");
cleanValue = Regex.Replace(intVal, " ", "").Replace(@"\(", "").Replace(@"\)", "").Replace(",", "").Replace("/", "").Replace("-", "");
cleanValue = Regex.Replace(intVal, " ", "").Replace("[()]", "").Replace(",", "").Replace("/", "").Replace("-", "");
cleanValue = Regex.Replace(intVal, " ", "").Replace(@"[^a-zA-Z]", "").Replace(",", "").Replace("/", "").Replace("-", "");
None of them worked, after I went through the code, I just see the space between "e" and "(" deleted ". Did I miss something?
In case someone wants to see functionwhich one is used here, this is:
public static string CleanExtra(string intVal)
{
string cleanValue;
if (intVal == null)
{
throw new System.ArgumentException("Value cannot be null", "original");
}
else
{
//cleanValue = Regex.Replace(intVal, " ", "").Replace("(", "").Replace(")", "").Replace(",", "").Replace("/", "").Replace("-", "");
//cleanValue = Regex.Replace(intVal, " ", "").Replace(@"\(", "").Replace(@"\)", "").Replace(",", "").Replace("/", "").Replace("-", "");
//cleanValue = Regex.Replace(intVal, " ", "").Replace("[()]", "").Replace(",", "").Replace("/", "").Replace("-", "");
cleanValue = Regex.Replace(intVal, " ", "").Replace(@"[^a-zA-Z]", "").Replace(",", "").Replace("/", "").Replace("-", "");
}
return cleanValue;
}