-2

I have a list of strings which has got some characters in it. enter image description here

On viewing it in HTML viewer I get the following

enter image description here

I tried line.Replace() to remove some special characters but it doesn't work.

Marnen Laibow-Koser
  • 5,585
  • 1
  • 26
  • 30
Newton Sheikh
  • 1,358
  • 1
  • 18
  • 40
  • You should take a look at this question. http://stackoverflow.com/questions/1120198/most-efficient-way-to-remove-special-characters-from-string – Greg Jun 12 '14 at 14:38
  • And maybe this: http://stackoverflow.com/questions/5459641/replacing-characters-in-c-sharp-ascii – tranceporter Jun 12 '14 at 14:39

2 Answers2

2

This code will remove any non-printable or non-ASCII characters using regex:

line = Regex.Replace(line, @"[^\u0021-\u007F]", string.Empty);
Andrew
  • 4,773
  • 15
  • 38
  • 56
0

You can filter it lke this :

var specialChars = new char[] {'-', '!', '*'}; // your all special chars
var newstr = string.Concat(line.ToCharArray().Where(c => !specialChars.Contains(c)));

Hope this helps.

Mukesh Modhvadiya
  • 2,138
  • 2
  • 24
  • 32