locked
Convert François to Francois in C# RRS feed

  • Question

  • Hi, 

    I am trying to convert special characters into ASCII characters.

    E.g. :-

    ('ö', 'o');
     ('ç', 'c');

    ('ş', 's');

    ('ı', 'i');
    ('ğ', 'g')

    ('ü', 'u');

    Is there any .net api available that can do this conversion?

    Monday, December 24, 2012 11:42 AM

Answers

All replies

  • For simple replace you can use string.Replace. To strip all of diacritics, see this article: http://blogs.msdn.com/b/michkap/archive/2007/05/14/2629747.aspx

    • Proposed as answer by Mike Feng Tuesday, December 25, 2012 5:10 AM
    • Marked as answer by HarshJain Tuesday, December 25, 2012 3:47 PM
    Monday, December 24, 2012 2:52 PM
  • Harsh Jain :

    Can you add your own conversion ? Hope the below helps .

      public static void Main(string[] args)
            {
                var input = "François";
                Dictionary<char, char> lookup = new Dictionary<char, char>();
                lookup.Add('ö', 'o');
                lookup.Add('ç', 'c');
                lookup.Add('ş', 's');
                lookup.Add('ı', 'i');
                lookup.Add('ğ', 'g');
                lookup.Add('ü', 'u');
                var result = new String(input.Select(x => (lookup.ContainsKey(x) ? lookup[x] : x)).ToArray());
                Console.WriteLine("{0} , {1} ",input, result.ToString());           
             }
            

    Tuesday, December 25, 2012 3:42 PM
  • Thanks Viorel. I am able to solve the issue.
    Tuesday, December 25, 2012 3:48 PM