-1

I know the accent i want to add to the letter ex: "´" and i know the letter i want to add it to ex:"a", and i want the final result to be á. But this has to work with at least 5 letters: a,e,i,o,u AND 4 accent "´","","^","~".Right now i am working on a function with several diferentecase's`. Is there a better way to do this?

Method i am using right now: Letra: letter ; caraterEspecial: specialCharater

switch (caraterEspecial)
            {
                case "´":
                    switch (letra)
                    {
                        case "a":
                            letra= "á";
                            break;
                        case "e":
                            letra= "é";
                            break;
                        case "i":
                             letra= "í";
                            break;
                        case "o":
                             letra= "ó";
                            break;
                        case "u":
                             letra= "ú";
                            break;
                    }
                    break;

                case "`":
                    switch (letra)
                    {
                        case "a":
                            letra= "à";
                            break;
                        case "e":
                            letra= "è";
                            break;
                        case "i":
                            letra= "ì";
                            break;
                        case "o":
                            letra= "ò";
                            break;
                        case "u":
                            letra= "ù";
                            break;
                    }
                    break;

                case "~":
                    switch (letra)
                    {
                        case "a":
                            letra= "ã";
                            break;
                        case "o":
                            letra = "õ";
                            break;
                    }
                    break;

                case "^":
                    switch (letra)
                    {
                        case "a":
                            letra= "â";
                            break;
                        case "e":
                            letra= "ê";
                            break;
                        case "i":
                            letra= "î";
                            break;
                        case "o":
                            letra= "ô";
                            break;
                        case "u":
                            letra = "û";
                            break;
                    }
                    break;
            }

For the accepted answer is a good list to use:

http://www.fileformat.info/info/unicode/block/combining_diacritical_marks/list.htm

meme
  • 597
  • 1
  • 10
  • 23
  • https://www.bing.com/search?q=c%23+add+diacritical+marks, in particular http://stackoverflow.com/questions/249087/how-do-i-remove-diacritics-accents-from-a-string-in-net shows reverse process which will help with finding right methods – Alexei Levenkov Apr 13 '16 at 14:58
  • @TimSchmelter If you do not have an answer to give please don't assume things. Thanks. – meme Apr 13 '16 at 15:13

2 Answers2

9

You can add a Unicode combining acute accent (U+0301). This will generate a 2-character sequence that is displayed as a character with accent.

If needed, you can normalize this string to a canonical form.

Ex.:

string s = "a";
s += "\u0301";
s = s.Normalize();
king_nak
  • 11,313
  • 33
  • 58
  • Note that this is still extremely culture specific, so it's not necessarily any better from simply having a dictionary for the mappings or something like that. Unicode tricks are fun, but different languages still treat similar concepts differently. – Luaan Apr 13 '16 at 15:01
  • When i try to use this code: http://www.fileformat.info/info/unicode/char/223c/index.htm They stay separated. How do i fix it? – meme Apr 13 '16 at 15:23
  • you have to watch out that you use _combining_ characters. combining tilde is U+0303 – king_nak Apr 13 '16 at 15:24
0

Easily you can use the replace method, but your question is incomplete. You should send the function , piece of code.

I would just use a s.replace('a','á'), maybe it's banal, but you don't have to deal too much, if letters are single like that.

Marco smdm
  • 1,020
  • 1
  • 15
  • 25