动态添加变音符号到角色

动态添加变音符号到角色

本文介绍了动态添加变音符号到角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿朋友!

我正在尝试创建一个将变音符号添加到字符的函数:

Hey friends!

I''m trying to create a function that adds diacritics to a character :

private static char AddDiacritics(char Letter, char Character)
{
   return (modified letter);
}



例如,如果我调用函数AddDiacritics(''e'', ''\"'');,我希望该函数返回字符ë.
如果我调用函数AddDiacritics(''u'', ''^'');,我希望函数返回û

框架中对此有某种支持吗?

谢谢,

Eduard



For example, if I call the function AddDiacritics(''e'', ''\"''); I want the function to return the character ë.
If I call the function AddDiacritics(''u'', ''^''); I want the function to return û

Is there some kind of support in the framework for this?

Thanks,

Eduard

推荐答案


Dictionary<char, Dictionary<char,char>> lookupTable = new Dictionary<char, Dictionary<char,char>>;
static MyClass(){
 lookupTable[''a''] = new Dictionary<char,char>();
 lookupTable[''a''][''"''] = ''ä'';
 lookupTable[''a''][''o''] = ''å'';
 // ... etc



我不确定ASCII集中是否有一套标准的变音标记,使用Unicode中的变音标记也没有多大意义,因为如果用户可以输入它们,则他们可以直接输入他们想要的字符.使用ANSI(西欧)时需要的是坟墓(è),尖锐的(é),变音符(ä),回旋符(â),圆环(å),斜线(ø),caron(š),波浪号(ñ)和塞地拉(ç);用于标记它们的明智字符将是',',,^,o,v,〜和c.在ANSI集中还包括eth和thorn,它们并不是正常字符的变音符号; oe和ae



I''m not sure if there is even a standard set of diacritical marks from the ASCII set, and there''s not much point using the ones in Unicode since if the user can enter those, they can enter the character they want directly. Those you need for ANSI (Western Europe) are grave (è), acute (é), umlaut (ä), circumflex (â), ring (å), slash (ø), caron (š), tilde (ñ) and cedila (ç); sensible characters to use to mark them would be `, '', ", ^, o, v, ~ and c. In the ANSI set there are also eth and thorn, which are not really diacritics of a normal character; oe and ae diphthongs; and the German ß, to think about.


enum Diacritic
{
    //"é"
    Acute,
    //"è"
    Grave,
    //"ê"
    Circonflexe,
    ...
}

//supported letters for e
static Dictionary<Diacritic, char> letterE;
//supported letters for a
static Dictionary<Diacritic, char> letterA;
//supported letters
static Dictionary<char, Dictionary<Diacritic, char>> letters;

//call this function to initialize dictionaries
//or put its code it a static constructor
static void Init()
{
    //all possibilities for "e"
    letterE = new Dictionary<Diacritic, char>();
    letterE[Diacritic.Acute] = 'é';
    letterE[Diacritic.Grave] = 'è';
    letterE[Diacritic.Circonflexe] = 'ê';
    ...

    //all possibilities for "a"
    letterA = new Dictionary<Diacritic, char>();
    letterA[Diacritic.Grave] = 'à';
    letterA[Diacritic.Circonflexe] = 'â';
    ...

    //supported letters
    letters = new Dictionary<char, Dictionary<Diacritic, char>>();
    letters.Add('a', letterA);
    letters.Add('e', letterE);
    ...
}

//will throw a KeyNotFoundException if the requested character doesn't exist
static char AddDiacritics(char letter, Diacritic diacritic)
{
    return letters[letter][diacritic];
}



这段代码不是很优雅,但是我不确定是否存在针对该问题的更优雅的解决方案...



This code is not very elegant but I am not sure if a more elegant solution exists for that problem...


这篇关于动态添加变音符号到角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 02:45