Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

seperate out name

Status
Not open for further replies.

scrsadmin

Technical User
May 3, 2004
62
US
I have to build a way to seperate out First name middle name and last name in a txt file. This comes in as a csv that looks like this;
firstname middlename lastname, emailaddress, userid

What i need is to be able to serapte out each part of the name. I tried using array but not all names have middlename so i get a out if range on the names thats only has a first and last. I would like to be able to test for first middle and last and somehow pull each one into a variable that i can use latter in the script. And ideas would be great.

namearray = Split(Fullname," ")
Firstname = namearray(0)
Middlename = namearray(1)
Lastname = namearray(2)

WScript.Echo Firstname
WScript.Echo Middlename
WScript.Echo Lastname
 
This is what i have for the name part but i get an error (Subscript out of range:)
if the name field only has two names and not three.

MyArray = Split(lineRead,",")
' MyArray(0) contains "FullName".
' MyArray(1) contains "spaces".
' MyArray(2) contains "email".

'set MyArray(1) to uppercase
Fullname = UCase(MyArray(0))
Email = (MyArray(2))
WScript.Echo Fullname & " " & Email



namearray = Split(Fullname," ")

If namearray(0) <> "" Then
Firstname = namearray(0)
End If
If namearray(2) <> "" Then
Middlename = namearray(1)
Lastname = namearray(2)
Else
Lastname = namearray(1)
End If



WScript.Echo Firstname
WScript.Echo Middlename
WScript.Echo Lastname
 
Forgive me but i don't understand how ubound will help.

The array has three parts
' MyArray(0) contains "FullName".
' MyArray(1) contains "spaces".
' MyArray(2) contains "email".

Part one or myarray(0) has the entire name, first middle and last.
How can i test against myarray(0) to see if all three parts are there and if not react on it.

 
UBound() returns the upper limit of an array.
If there is no middle name then your upper limit will be one less than if there were a middle name.
 
Okay here is what i have and it seems to be working.
MyArray = Split(lineRead,",")
' MyArray(0) contains "FullName".
' MyArray(1) contains "spaces".
' MyArray(2) contains "email".

'set MyArray(1) to uppercase
Fullname = UCase(MyArray(0))
Email = (MyArray(2))
WScript.Echo Fullname & " " & Email



namearray = Split(Fullname," ")
testname = UBound(namearray)

If testname = "2" Then
Firstname = namearray(0)
Middlename = namearray(1)
Lastname = namearray(2)

ElseIf testname = "1" Then
Firstname = namearray(0)
Middlename = " "
Lastname = namearray(1)
Else
WScript.Echo "Name not right"
End If



WScript.Echo Firstname
WScript.Echo Middlename
WScript.Echo Lastname


Thanks for your help and patiences.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top