-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,959
  • 1
  • 28
  • 33
Newton Sheikh
  • 1,376
  • 2
  • 19
  • 42
  • 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,953
  • 15
  • 40
  • 58
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,178
  • 2
  • 27
  • 32