Created
April 28, 2012 15:26
-
-
Save mmuell/2519806 to your computer and use it in GitHub Desktop.
Turns out AutoCad doesn't allow characters with accents within Layer Names. I created the following static class to remove the accents on a provided string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
namespace MCS.DXF.Utility | |
{ | |
public static class AccentUtility | |
{ | |
private static class ReplacementHolder | |
{ | |
private static Dictionary<char, char> _replacements; | |
static ReplacementHolder() | |
{ | |
_replacements = new Dictionary<char, char>(); | |
_replacements.Add((char)192, 'A'); | |
_replacements.Add((char)193, 'A'); | |
_replacements.Add((char)194, 'A'); | |
_replacements.Add((char)195, 'A'); | |
_replacements.Add((char)196, 'A'); | |
_replacements.Add((char)197, 'A'); | |
_replacements.Add((char)198, 'A'); | |
_replacements.Add((char)199, 'C'); | |
_replacements.Add((char)200, 'E'); | |
_replacements.Add((char)201, 'E'); | |
_replacements.Add((char)202, 'E'); | |
_replacements.Add((char)203, 'E'); | |
_replacements.Add((char)204, 'I'); | |
_replacements.Add((char)205, 'I'); | |
_replacements.Add((char)206, 'I'); | |
_replacements.Add((char)207, 'I'); | |
_replacements.Add((char)208, 'D'); | |
_replacements.Add((char)209, 'N'); | |
_replacements.Add((char)210, 'O'); | |
_replacements.Add((char)211, 'O'); | |
_replacements.Add((char)212, 'O'); | |
_replacements.Add((char)213, 'O'); | |
_replacements.Add((char)214, 'O'); | |
_replacements.Add((char)215, 'x'); | |
_replacements.Add((char)216, 'O'); | |
_replacements.Add((char)217, 'U'); | |
_replacements.Add((char)218, 'U'); | |
_replacements.Add((char)219, 'U'); | |
_replacements.Add((char)220, 'U'); | |
_replacements.Add((char)221, 'Y'); | |
_replacements.Add((char)222, 'P'); | |
_replacements.Add((char)223, 'B'); | |
_replacements.Add((char)224, 'a'); | |
_replacements.Add((char)225, 'a'); | |
_replacements.Add((char)226, 'a'); | |
_replacements.Add((char)227, 'a'); | |
_replacements.Add((char)228, 'a'); | |
_replacements.Add((char)229, 'a'); | |
_replacements.Add((char)230, 'a'); | |
_replacements.Add((char)231, 'c'); | |
_replacements.Add((char)232, 'e'); | |
_replacements.Add((char)233, 'e'); | |
_replacements.Add((char)234, 'e'); | |
_replacements.Add((char)235, 'e'); | |
_replacements.Add((char)236, 'i'); | |
_replacements.Add((char)237, 'i'); | |
_replacements.Add((char)238, 'i'); | |
_replacements.Add((char)239, 'i'); | |
_replacements.Add((char)240, 'o'); | |
_replacements.Add((char)241, 'n'); | |
_replacements.Add((char)242, 'o'); | |
_replacements.Add((char)243, 'o'); | |
_replacements.Add((char)244, 'o'); | |
_replacements.Add((char)245, 'o'); | |
_replacements.Add((char)246, 'o'); | |
_replacements.Add((char)247, 'o'); | |
_replacements.Add((char)248, 'o'); | |
_replacements.Add((char)249, 'u'); | |
_replacements.Add((char)250, 'u'); | |
_replacements.Add((char)251, 'u'); | |
_replacements.Add((char)252, 'u'); | |
_replacements.Add((char)253, 'y'); | |
_replacements.Add((char)254, 'b'); | |
_replacements.Add((char)255, 'y'); | |
} | |
public static Dictionary<char, char> Replacements | |
{ | |
get { return _replacements; } | |
} | |
} | |
public static string RemoveAccents(string orig) | |
{ | |
string value = orig; | |
foreach (KeyValuePair<char, char> keyValuePair in ReplacementHolder.Replacements) | |
{ | |
value = value.Replace(keyValuePair.Key, keyValuePair.Value); | |
} | |
return value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment