I am new to C#. Say that I have a string like this:
string test = 'yes/, I~ know# there@ are% invalid£ characters$ in& this* string^";
If I wanted to get rid of a single invalid symbol, I would do:
if (test.Contains('/'))
{
test = test.Replace("/","");
}
But is there a way I can use a list of symbols as argument of the Contains
and Replace
functions, instead of deleting symbols one by one?
char[]
. You need to usechar[] x = {'/'};
Thentest.Replace(x, "")
; Ortest.Replace('/', \"");
– Bioplasmstring result = Regex.Replace(test, @"[^\p{L}\d\s,.;:!?\-]", "");
- we spare letters, digits, white spaces and some punctuations – Liverwurst