views:

798

answers:

5

I'm currently being visually assaulted by all of the names that are being displayed and entered on one of my systems. Basically, users have use of an on-screen keyboard and don't tend to write things in neatly! I.e. John Smith ends up getting entered as JOHN SMITH or john smith.

I want a way to neatly enter names and display them. I've written a method that goes through all the names and does just this, but it's about 20 lines of code and not very efficient.

Is there a good way of achieving this? I have tried .ToTitleCase(), but it doesn't work for cases such as O'Brien and McCarthy? Is there anything out there than can do this, nicely? My code at the moment basically has a list of special cases and goes through and manipulates them if they contain the special case... It's not the most efficient thing in the world though.

Thanks in advance.

A: 

Probleme will arise when Chinese, Japanese, Arabic, Hebrew and many other people from everywhere will join your system...

Think global. It's already hard to do with Irish people :P

Perhaps show to your users how there name will be displayed, they'll be a bit more careful.

Think Before Coding
+2  A: 

As you've already suggested there is no real easy way to achieve this without having to handle the special cases that always get thrown up with names.

This question has several suggestions that may be of help to you:

How do I capitalize first letter of first name and last name in C#?

Andy Rose
+5  A: 

Does it really matter? If a user doesn't care whether their name is all upper case or all lower case then I'd suggest that you don't need to worry about that either.

Users who do care about how their name is capitalised will presumably enter their name with care.

If you start to mess around with capitalisation then there's the risk of getting it wrong and offending a user.

Surely there are other aspects of the system that warrant more attention...

Richard Ev
"Surely there are other aspects of the system that warrant more attention..." Who are you, and how have you seen my source code =P? Heh. I'm in agreement, it's a mine field I don't want to get into. I will probably change to using full name and friendly name.
GenericTypeTea
I have a similar issue with an application I've been working on - my customers' names look terrible when I see them in a list. I have taken the above approach regarding capitalisation, and just take a deep calming breath whenever I see the user list. :-)
Richard Ev
A: 

Also consider that for some cultures, it's surname first followed by given name, simply not having a surname.

Additionally some names are more than just two or three words. Consider:

  • Manuel de la Cruz
  • Shawn van DeMark
  • Alice St. Claire
  • Anna Eastman-Smith
  • Po Yin
  • Ho Chi Minh
  • Julia Running Bear
  • Talks to Spirits

(The last was a Native American given name without a surname.)

Ants
+1  A: 

I believe formatting matters. Badly formatted names look bad in a list or on an envelope (at least in my eyes). I always feel the urge to format them correctly. Its almost an obsession of mine.

So DanD, this is how I do it: When a user enters their full name in my app, i trim() all the names, remove double spaces and then format all the names in Proper Case. I then display then names to the user with a prompt like: "Did we format your names correctly?" and give the user the opportunity to correct formatting. After this, I just save the names. Good luck.