How can I reformat a name ("Doe, John D") to remove middle initial and comma, and show only first name, then last name? ("John Doe")

Posted on 2007-09-28
Last Modified: 2010-04-16
Well the subject pretty much sums it up.. Can anyone show me the best way to do this using C#?

Thanks much,

Question by:OddiC
    LVL 10

    Accepted Solution

    You can use Regular expressions like this:

    string testString = "Doe, John D";

                Regex firstNameRegex = new Regex(",.+ ");
                Regex lastNameRegex = new Regex(".+,");

                string firstName = firstNameRegex.Match(testString).Value.Substring(1).Trim(); ;
                string lastName= lastNameRegex.Match(testString).Value.Substring(0,lastNameRegex.Match(testString).Value.Length-1).Trim();

                textBox1.Text = firstName +" "+ lastName;

    Author Comment

    Awesome. Thank you dkloeck!
    LVL 10

    Expert Comment

    no problem ^_^

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    745 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

    14 Experts available now in Live!

    Get 1:1 Help Now