Awesome diacritics striping:)



  • Everything is awesome in this method: the name, going to upper and lower with no sense at all, replacing stuff which cannot be there after previous replace. This is a really robust when you want to add additional language to your app:)

    [code]
    public static string Umlaut2Common(string str)
    {
    //Poland
    str = str.ToUpper().Replace("Ą", "A");
    str = str.ToLower().Replace("ą", "a");

            str = str.ToUpper().Replace("Ę", "E");
            str = str.ToLower().Replace("ę", "e");
    
            str = str.ToUpper().Replace("Ć", "C");
            str = str.ToLower().Replace("ć", "c");
    
            str = str.ToUpper().Replace("Ł", "L");
            str = str.ToLower().Replace("ł", "l");
    
            str = str.ToUpper().Replace("Ń", "N");
            str = str.ToLower().Replace("ń", "n");
    
            str = str.ToUpper().Replace("Ó", "O");
            str = str.ToLower().Replace("ó", "o");
    
            str = str.ToUpper().Replace("Ś", "S");
            str = str.ToLower().Replace("ś", "s");
    
            str = str.ToUpper().Replace("Ź", "Z");
            str = str.ToLower().Replace("ż", "z");
    
            str = str.ToUpper().Replace("Ż", "Z");
            str = str.ToLower().Replace("ż", "z");
    
            // Czech
            str = str.ToLower().Replace("ě", "e");
            str = str.ToLower().Replace("é", "e");
            str = str.ToLower().Replace("š", "s");
            str = str.ToLower().Replace("č", "c");
            str = str.ToLower().Replace("ř", "r");
            str = str.ToLower().Replace("ž", "z");
            str = str.ToLower().Replace("ý", "y");
            str = str.ToLower().Replace("á", "a");
            str = str.ToLower().Replace("í", "i");
            str = str.ToLower().Replace("ů", "u");
            str = str.ToLower().Replace("ú", "u");
    
            return str;
        }[/code]

  • Trolleybus Mechanic

    @Wladek said:

    Everything is awesome
     

    And that's yet another week I'll have that earworm.


  • ♿ (Parody)

    But...but...it's all commented out!

    More to the point, I think this belongs in the sidebar, unless there's a question buried in the wall of code.



  • @Wladek said:

    Everything is awesome in this method: the name, going to upper and lower with no sense at all, replacing stuff which cannot be there after previous replace. This is a really robust when you want to add additional language to your app:)

    public static string Umlaut2Common(string str)
            {
                //Poland
                str = str.ToUpper().Replace("Ą", "A");
                str = str.ToLower().Replace("ą", "a");
    
                str = str.ToUpper().Replace("Ę", "E");
                str = str.ToLower().Replace("ę", "e");
    
                str = str.ToUpper().Replace("Ć", "C");
                str = str.ToLower().Replace("ć", "c");
    
                str = str.ToUpper().Replace("Ł", "L");
                str = str.ToLower().Replace("ł", "l");
    
                str = str.ToUpper().Replace("Ń", "N");
                str = str.ToLower().Replace("ń", "n");
    
                str = str.ToUpper().Replace("Ó", "O");
                str = str.ToLower().Replace("ó", "o");
    
                str = str.ToUpper().Replace("Ś", "S");
                str = str.ToLower().Replace("ś", "s");
    
                str = str.ToUpper().Replace("Ź", "Z");
                str = str.ToLower().Replace("ż", "z");
    
                str = str.ToUpper().Replace("Ż", "Z");
                str = str.ToLower().Replace("ż", "z");
    
                // Czech
                str = str.ToLower().Replace("ě", "e");
                str = str.ToLower().Replace("é", "e");
                str = str.ToLower().Replace("š", "s");
                str = str.ToLower().Replace("č", "c");
                str = str.ToLower().Replace("ř", "r");
                str = str.ToLower().Replace("ž", "z");
                str = str.ToLower().Replace("ý", "y");
                str = str.ToLower().Replace("á", "a");
                str = str.ToLower().Replace("í", "i");
                str = str.ToLower().Replace("ů", "u");
                str = str.ToLower().Replace("ú", "u");
    
                return str;
            }

    FTFY



  • The method should be marked as an Extension to the String class and be named more appropriately.

    debug.writeline(strangeForeignText.AmericaFuckYeah()) 


  • Discourse touched me in a no-no place

    For a bonus, what would be the right way to do the transform?



  • @dkf said:

    For a bonus, what would be the right way to do the transform?

    If you MUST have ASCII representations of each character, I suggest using the Unicode description of each character, separated by newlines.



  • @dkf said:

    For a bonus, what would be the right way to do the transform?

    That depends on which input characters you need to mangle and which output characters are acceptable. NFD only gives a partial solution, although it's certainly a good way of starting to build up a translation table.



  • @dkf said:

    For a bonus, what would be the right way to do the transform?
    Renegotiate the spec.


Log in to reply