72
1
using System; using System.Text; using System.Linq; using System.Diagnostics;
2
3
public static class Program
4
{
5
// Based on http://www.codeproject.com/Articles/13503/Stripping-Accents-from-Latin-Characters-A-Foray-in
6
// Proper Normalization
7
public static string UnicodeToANSI(this string s)
8
{
9
var sb = new StringBuilder();
10
sb.Append(s.Normalize(NormalizationForm.FormKD)
11
.Where(x => (x > 30 && x <= 255))
12
.ToArray());
13
return sb.ToString();
14
}
15
16
//ANSI characters 32 to 127 correspond to those in the 7-bit ASCII character set,
17
public static string ReducetoASCII(this string s)
18
{
19
StringBuilder sb = new StringBuilder(s.Length);
20
foreach (char c in s)
21
{
22
if ((int)c > 255) // remove chars > 127
23
continue;
24
if ((int)c < 32) // remove control characters
Cached Result