I am using ASP.NET MVC3, C#, .NET 4.5
I need to remove any "Escape" characters which seem to be appearing in a HTML file.
I was trying:
NewHtml = OldHtml.Replace("0x1B","")
But I think I have something wrong here. Please advise.
I am using ASP.NET MVC3, C#, .NET 4.5
I need to remove any "Escape" characters which seem to be appearing in a HTML file.
I was trying:
NewHtml = OldHtml.Replace("0x1B","")
But I think I have something wrong here. Please advise.
The replace is correct but I doubt that your string is right..
You need to convert the hex value first to a character and then to a string:
string esc = ((char)0x1b).ToString()
To remove the one character in your question use :
NewHtml = OldHtml.Replace( ((char)0x1b).ToString(), "" );
To remove several characters you can do this:
var chars = new char[] { (char)27, (char)0x1b, '\t', '~' };
string NewHtml = OldHtml;
foreach (var c in chars ) NewHtml = str.Replace(c.ToString(), string.Empty);
I have combined a few different ways to create characters.
Or you can, and probably should go for a Regular Expression..
Several other solutions can be found here..