Convert Non-Standard ASCII Characters

Posted on 2006-05-02
Last Modified: 2012-06-27
Is there any method available in C# that will convert any non-standard ASCII characters (characters > binary 128) into its equivalent standard ASCII characters.  Basically, I need to replace any 'ñ' in my string to 'n', 'á' into 'a', 'ú' into 'u', and others.  Aside from calling the String.Replace method, is there any other way without listing down/hard-coding all the non-standard ASCII characters with the corresponding replacement standard ASCII character.

Thanks for the help in advance.
Question by:rafrancisco
    LVL 55

    Expert Comment

    by:Jaime Olivares
    I have never seen this function but you can create a table and a function, something like:

    private char[] AsciiConversionTable = new char[128] { 'C','u','e','a','a','a','a','c','e','e','e','i','i','i','A','A', .....ETC...... };

    public char ToAscii7Bits(char ascii)
         return (ascii<128) ? ascii : AsciiConversionTable[ascii-128];
    LVL 6

    Expert Comment

    The "non-standard ASCII characters" which you listed are Latin characters.
    In fact, the character 'ú' is not 'u', but 'w'.

    public char LatinToEnglishChar(char ascii)
         return (ascii<131) ? ascii : ascii-131;
    LVL 55

    Accepted Solution

    >The "non-standard ASCII characters" which you listed are Latin characters.
    >In fact, the character 'ú' is not 'u', but 'w'.

    I don't know how you have concluded that. non-standard ASCII characters are almost all possible west european-languages characters (spanish, french, german, portugaise, etc.)
    In spanish and many other languages ú is not w, is just an u with accent, even it is "legal" to represent without "adornments" when expressed in uppercase, like U.
    There are some interesting exceptions like in german where: ü can be represented as "ue", ä as "ae" and ß as "ss".

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now