Reputation: 4920
what is the equivalent of below:
contact.name.Replace("(", "").Replace(")", "").Replace("-", "").Replace(" ", "");
Thanks
Upvotes: 0
Views: 98
Reputation: 89499
Using LINQ:
var s = "abcd 238(23)2342-23";
var exclusion = "()- ";
var result = new string(s.ToCharArray().Where (x => !exclusion.Contains(x)).ToArray());
or
var s = "abcd 238(23)2342-23";
var result = new string(s.ToCharArray().Where (x => !"()- ".Contains(x)).ToArray());
Upvotes: 1
Reputation: 7807
StringBuilder will be more effecient if you're doing more than a few replacements.
Upvotes: 0