Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Split Name Field

Split Name Field

Scheduled Pinned Locked Moved C#
databasehelpquestion
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kruegersck
    wrote on last edited by
    #1

    All - I am looking for an easy solution to split a name field from another DB. I am converting data from on DB to another. In the source DB the name field is one field that is free form. Here are some examples of names: John Smith John E Smith DR John E Smith DR John Smith In my db the name field is first and last name (separate fields). Any suggestions? As always thanks for your help! sk

    L M V P 5 Replies Last reply
    0
    • K kruegersck

      All - I am looking for an easy solution to split a name field from another DB. I am converting data from on DB to another. In the source DB the name field is one field that is free form. Here are some examples of names: John Smith John E Smith DR John E Smith DR John Smith In my db the name field is first and last name (separate fields). Any suggestions? As always thanks for your help! sk

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      how about Split method ? http://msdn.microsoft.com/en-us/library/b873y76a.aspx[^]

      1 Reply Last reply
      0
      • K kruegersck

        All - I am looking for an easy solution to split a name field from another DB. I am converting data from on DB to another. In the source DB the name field is one field that is free form. Here are some examples of names: John Smith John E Smith DR John E Smith DR John Smith In my db the name field is first and last name (separate fields). Any suggestions? As always thanks for your help! sk

        M Offline
        M Offline
        musefan
        wrote on last edited by
        #3

        Its a tricky one because you have a number of possibilities, i.e. Title and middle names. If this was a one of process I would use manual intervention, but would also have fields for title. Do you want to retain the title anywhere? where should the middle name be included? I would put the middle name with the forename if I only had two fields (forename, surname) Why don't you try something like...

        void GetMeSomeNames(string fullname, out string forename, out string surname)
        {
        forename = surname = "";
        string[] names = fullname.Split(' ', StringFormatOptions.RemoveEmptyEntries);
        if(names.length == 0)
        return;
        if(names.length == 1)
        {
        forename = names[0];//or surname if preferred
        return;
        }

        bool hasTitle = false;
        switch(names[0].ToLowerInvarient())
        {
        case "dr":
        hasTitle = true;
        case "mr":
        hasTitle = true;
        //etc...
        }
        for(int i = (hasTitle ? 1 : 0); i < names.length - 1; i++)
        forename += names[i] + " ";
        forename = forename.Trim();
        surname = names[names.length-1];
        }

        Life goes very fast. Tomorrow, today is already yesterday.

        1 Reply Last reply
        0
        • K kruegersck

          All - I am looking for an easy solution to split a name field from another DB. I am converting data from on DB to another. In the source DB the name field is one field that is free form. Here are some examples of names: John Smith John E Smith DR John E Smith DR John Smith In my db the name field is first and last name (separate fields). Any suggestions? As always thanks for your help! sk

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Essentially, it is a tough task. There may be names that just have a first and last or first, middle and last and it may contains salutations (Dr, Mr, Mrs, etc.) also. Writing a script to take care of all of these scenarios is really difficult. Just give it a try.

          1 Reply Last reply
          0
          • K kruegersck

            All - I am looking for an easy solution to split a name field from another DB. I am converting data from on DB to another. In the source DB the name field is one field that is free form. Here are some examples of names: John Smith John E Smith DR John E Smith DR John Smith In my db the name field is first and last name (separate fields). Any suggestions? As always thanks for your help! sk

            V Offline
            V Offline
            V 0
            wrote on last edited by
            #5

            You need some sort of agreement on what is considered first name and what is considered last name. You could also have the following eg: John Smith Peeters John Edward Smith John Edward Smith Peeters John Edward Smith-Peeters John E. Smith-Peeters ... You could filter Dr, DR, Mr, Ms, ... as a title and one letter words (with or without . like E or E.) can be considered firstnames, but I'm not sure if it's possible to have a 100% correct algorithm. good luck.

            V.
            Stop smoking so you can: Enjoy longer the money you save. Moviereview Archive

            1 Reply Last reply
            0
            • K kruegersck

              All - I am looking for an easy solution to split a name field from another DB. I am converting data from on DB to another. In the source DB the name field is one field that is free form. Here are some examples of names: John Smith John E Smith DR John E Smith DR John Smith In my db the name field is first and last name (separate fields). Any suggestions? As always thanks for your help! sk

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              I don't think it can be done without human intervention. At best you could put the last element in the last name field and everything else in the first name field. Then review any first names that contain a SPACE.

              L 1 Reply Last reply
              0
              • P PIEBALDconsult

                I don't think it can be done without human intervention. At best you could put the last element in the last name field and everything else in the first name field. Then review any first names that contain a SPACE.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                PIEBALDconsult wrote:

                At best you could put the last element in the last name field and everything else in the first name field.

                That would yield a lot of problems where I live, as: 1) a lot of last names consist of two or three words, such as "Miel De Schepper" and "Jan van der Spiegel" (first names are Miel/Jan); here you should at least check for "de", "van der" and "van de" (all possible capitalizations) and when they occur they are part of the last name. 2) first names could be composite ("Jean-Paulus") and last names could be composite ("Paulus-Beeldens"); now what when one of them is composite, the hyphen is missing, and the middle word of three could be a second half of the first name, or the first half of the last name (say "Jean Paulus Beeldens")? I am 100% sure there isn't an algorithm that solves the problem, and IMO the best fit algorithm is very region dependent. :)

                Luc Pattyn


                I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups