473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to separate names into first last and middle initial

2
Im trying to Separate Last name, First Name and Middle Initial. File is csv format, here is an example:

Expand|Select|Wrap|Line Numbers
  1. A0001,3,Y,13,LU, 
  2. A0001,3,Y,13,CLARK P, 
  3. A0001,3,Y,13,SMITH JOHN, 
  4. A0001,3,Y,13,BEAL KRISS J, 
  5. A0001,3,Y,13,THOMAS A CLIFF C, 
  6. A0001,3,Y,13,DEW III ROBERT H, 
Output fields :
Expand|Select|Wrap|Line Numbers
  1.                Last name               First name           Initial    
  2.                   LU                     
  3.                   CLARK                   P  
  4.                   SMITH                   JOHN  
  5.                   BEAL                    KRISS                J  
  6.                   THOMAS A                CLIFF                C  
  7.                   DEW III                 ROBERT               H 
Thanks In Advance.
Sep 24 '10 #1
2 3163
Aimee Bailey
197 Expert 100+
Normally all you need to do is read split up the data by line breaks, then by the comma. Heres a simple function that can do that:

Expand|Select|Wrap|Line Numbers
  1. Public Function ReadCSV(ByVal data As String) As List(Of String())
  2.         Dim result As New List(Of String())
  3.         Dim lines As String() = data.Split(vbCrLf.ToString())
  4.  
  5.         For Each line As String In lines
  6.             result.Add(line.Split(New Char() {","}, _
  7.                                   StringSplitOptions.RemoveEmptyEntries))
  8.         Next
  9.  
  10.         Return result
  11.     End Function
  12.  
And to use it:

Expand|Select|Wrap|Line Numbers
  1. Dim data As String = "A0001,3,Y,13,LU, " & vbCrLf & _
  2.                           "A0001,3,Y,13,CLARK P, " & vbCrLf & _
  3.                           "A0001,3,Y,13,SMITH JOHN, " & vbCrLf & _
  4.                           "A0001,3,Y,13,BEAL KRISS J, " & vbCrLf & _
  5.                           "A0001,3,Y,13,THOMAS A CLIFF C, " & vbCrLf & _
  6.                           "A0001,3,Y,13,DEW III ROBERT H, "
  7.  
  8.         For Each row In ReadCSV(data)
  9.             ListBox1.Items.Add(row(4))
  10.         Next
  11.  
Sep 26 '10 #2
!NoItAll
297 100+
Seems to me that you've been asked to fix broken data. If the firstname, lastname and middle initial were not entered in specific fields for their respective purposes - there is no clean way to retrieve it that way.
You will inevitably run into examples like
John Smith III
and
Smith John III
or
Smith III John

So unless you are going to read each entry and clean up the data - then you will likely wind up with some percentage of incorrectly mapped fields. If there's not a lot of data - fine, do it by hand. If there is, yikes.
Sep 26 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Calan | last post by:
I have a server-side ASP script that dynamically creates an input form from a database table. The table contains a field name, the table where values are stored, type of input control, value for a...
12
by: Gary | last post by:
I have a backend Database with just one main table in it (no form/queries etc) The network pc's have the front end database (with all the forms, queries,macros etc). These front ends are linked...
39
by: Joe Laughlin | last post by:
If I have a character array with "/some/file/directory/file_name", are there any functions / libraries that I could use to separate the directory ("some/file/directory") from the file name...
17
by: Joe Laughlin | last post by:
I've not used C much before, so I don't know how robust or good this code is. I'd appreciate any feedback or criticisms anyone has! Thanks, Joe #include <stdio.h> #include <string.h>
1
by: Prasanna Padmanabhan | last post by:
I want to process requests to certain image files that have a custom ..icon(32x32) extenstion with a custom .NET HttpHandler in order to be able to tap into Application events. This works fine...
8
by: Jeff S | last post by:
Please note that this question is NOT about any particular pattern - but about the general objective of separating out presentation logic from everything else. I'm trying to "get a grip" on some...
20
by: Luc Kumps | last post by:
(Sorry about the previous post, it got transmitted before it was complete) We try to separate implementation and interface defintions, but we run into a problem. I hope the guru's can solve this,...
3
by: janetager | last post by:
I have a field that has names in it in the format "last name, first name". I want code that will split this field for me at the comma so I can make 2 separate fields for last name and first name. ...
2
by: eduardoamfm | last post by:
Hi everybody! I have the following files: (MSC.080806.00, MSC.080806.01, MSC.080806.02...) each one has the same pattern, with two different START and STOP times and values: ... ...
4
by: Steven Simpson | last post by:
Stefan Ram wrote (in "More than one language in a page"): Is this a new trend of user-agent writers (Microformats, and now Google) staking claims on the @class namespace? I'm surely not the only...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.