1
新しい製品カテゴリが作成されたときに、Webレイヤのコンテンツフォルダにディレクトリを作成したいが、カテゴリ名がCirillycにあり、Cirillycのパスが適切でないため、フォルダに変換します。私はUnidecodeSharpForkを試してみましたが、ディレクトリ名にはうまくいきません。このような状況で他の選択肢はありますか?CirillycからLatinへの翻訳
新しい製品カテゴリが作成されたときに、Webレイヤのコンテンツフォルダにディレクトリを作成したいが、カテゴリ名がCirillycにあり、Cirillycのパスが適切でないため、フォルダに変換します。私はUnidecodeSharpForkを試してみましたが、ディレクトリ名にはうまくいきません。このような状況で他の選択肢はありますか?CirillycからLatinへの翻訳
あなたはmaluallyを音訳マップを実装しようとすることができます
// Capital letters should be transliterated by the same scheme
public class CaseInsensitiveComparer: IEqualityComparer<char> {
public bool Equals(char left, char right) {
return char.ToUpperInvariant(left) == char.ToUpperInvariant(right);
}
public int GetHashCode(char value) {
return char.ToUpperInvariant(value).GetHashCode();
}
}
...
// implement map manually
private static Dictionary<char, String> map =
new Dictionary<char, string>(new CaseInsensitiveComparer()) {
{'а', "a" },
{'б', "b" },
...
{'я', "ya" },
};
、それを使用します。
string source = "My string (Моя Строка)";
string result = string.Concat(source.Select(c => {
string st;
if (map.TryGetValue(c, out st))
return char.IsUpper(c) ? st.ToUpperInvariant() : st;
else
return c.ToString();
}));
テスト
// My string (Moya Stroka)
Console.Write(result);