locked
Format Name- First Middle Last

    Question

  • We are receiving - not well formatted First Name, Middle Name and Last Name separately. We have to convert it into proper format.

    Is there any C# class by which I can Format First Name, Middle Name and Last in proper format.

    1. john  as John

    2. mcdonlad as McDonlad

    3. bill o'reilly as Bill O'Reilly 

    Are there any Globalization and Localization specific rule can be applied?

    Is there anyway we can format Suffix and Prefix associated with Name's from  C# inbuild libraries.


    MPramod
    Friday, September 23, 2011 5:16 PM

Answers

  • Mpramod,

    You can format names to proper case like this:

    string name = "john mcdonald";
    
    
    
    string new_name = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(name);
    
    
    
    

     Although you make have to tap into some other library or write your own routine (implement IFormatProvider) to handle some of the other special cases.  I don't know of anything built into .NET that can detect a string and determine how it should be capitalized like the D in McDonald.  


    Tom Overton

     


    • Edited by Tom_Overton Friday, September 23, 2011 5:36 PM
    • Marked as answer by Mpramod Friday, September 23, 2011 7:07 PM
    Friday, September 23, 2011 5:27 PM
  • Same is :

    string Name = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase("your name");
    

    But as Tom explained, there is no in-built mehanism to capitalize D in McDonald name.


    Mitja
    • Marked as answer by Mpramod Friday, September 23, 2011 7:07 PM
    Friday, September 23, 2011 6:19 PM
  • Hi :)

    You can create a table (or list, anything - a collection) with the most  common names and first names (in your country, in the world). The table acts like a cache. When the string you receive is similar to one that exist in the table, call it a HIT. Otherwise, call it a MISS.

    in case of a HIT: use the name in the table.

    in case of a MISS: send it to a human operator :) Or implement a simple algorithm to guess the correct name. Then add it to the cache.

    Regards,

    andrei




    • Marked as answer by Mpramod Friday, September 23, 2011 7:07 PM
    • Edited by andrei - Friday, September 23, 2011 7:30 PM ("then add it to the cache". Your welcome, MPramod)
    Friday, September 23, 2011 6:56 PM

All replies

  • Mpramod,

    You can format names to proper case like this:

    string name = "john mcdonald";
    
    
    
    string new_name = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(name);
    
    
    
    

     Although you make have to tap into some other library or write your own routine (implement IFormatProvider) to handle some of the other special cases.  I don't know of anything built into .NET that can detect a string and determine how it should be capitalized like the D in McDonald.  


    Tom Overton

     


    • Edited by Tom_Overton Friday, September 23, 2011 5:36 PM
    • Marked as answer by Mpramod Friday, September 23, 2011 7:07 PM
    Friday, September 23, 2011 5:27 PM
  • Same is :

    string Name = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase("your name");
    

    But as Tom explained, there is no in-built mehanism to capitalize D in McDonald name.


    Mitja
    • Marked as answer by Mpramod Friday, September 23, 2011 7:07 PM
    Friday, September 23, 2011 6:19 PM
  • Hi :)

    You can create a table (or list, anything - a collection) with the most  common names and first names (in your country, in the world). The table acts like a cache. When the string you receive is similar to one that exist in the table, call it a HIT. Otherwise, call it a MISS.

    in case of a HIT: use the name in the table.

    in case of a MISS: send it to a human operator :) Or implement a simple algorithm to guess the correct name. Then add it to the cache.

    Regards,

    andrei




    • Marked as answer by Mpramod Friday, September 23, 2011 7:07 PM
    • Edited by andrei - Friday, September 23, 2011 7:30 PM ("then add it to the cache". Your welcome, MPramod)
    Friday, September 23, 2011 6:56 PM
  • Thank you Tom, Mitja, Andrei
    MPramod
    Friday, September 23, 2011 7:07 PM