Skip to content

Instantly share code, notes, and snippets.

@hervehobbes
Created July 11, 2014 09:22
Show Gist options
  • Save hervehobbes/dea1335d9d78a377f909 to your computer and use it in GitHub Desktop.
Save hervehobbes/dea1335d9d78a377f909 to your computer and use it in GitHub Desktop.
private string removeNonAsciiChar(string content)
{
content = Regex.Replace(content.Trim(), @"[^\u0000-\u007F]", string.Empty);
return Encoding.ASCII.GetString(
Encoding.Convert(
Encoding.UTF8,
Encoding.GetEncoding(
Encoding.ASCII.EncodingName,
new EncoderReplacementFallback(string.Empty),
new DecoderExceptionFallback()
),
Encoding.UTF8.GetBytes(content)
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment