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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I get the last name only from a full name string?

Status
Not open for further replies.

d1004

Programmer
May 9, 2002
78
US
My work place database design really sucks where they
include first and last name into one field.
However, I need to get the last name to compare with other field, but
I don't know how to do that in ASP.
I understand you can do that with C++ where you get all
the characters until white space, but can that concept
apply with ASP?
Thank you,
 
Try this:
<%
Dim sFullname, sFirstName, sMiddleName, sLastName
sFullName = &quot;John J Finklehymer&quot;
sFirstName = left(sFullName, instr(sFullName, &quot; &quot;))
sLastName = mid(sFullName, InStrRev(sFullName, &quot; &quot;))
sMiddleName = mid(sFullName, len(sFirstName)+1, len(sFullName)-len(sFirstname)-len(sLastname))
response.write &quot;<br>First name =&quot; & sFirstName
response.write &quot;<br>Last name =&quot; & sLastName
response.write &quot;<br>Middle name/initial =&quot; & sMiddleName
%>

Then all you have to worry about is
John J Finklehymer III and Finklehymer Jr.

Alternatively:
<%
Dim sFullname, sFirstName, sMiddleName, sLastName, a
a = split(sFullName)
select case Ubound(a)
case 0
response.write &quot;<br>First name =&quot; & a(0)
'response.write &quot;<br>Last name =&quot; & a(0) 'you choose
case 1
response.write &quot;<br>First name =&quot; & a(0)
response.write &quot;<br>Last name =&quot; & a(1)
case 2
response.write &quot;<br>First name =&quot; & a(0)
response.write &quot;<br>Middle name/initial =&quot; & a(1)
response.write &quot;<br>Last name =&quot; & a(2)
case 3
response.write &quot;<br>First name =&quot; & a(0)
response.write &quot;<br>Middle name/initial =&quot; & a(1)
response.write &quot;<br>Last name =&quot; & a(2)
response.write &quot;<br>Other=&quot; & a(3)
end select
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top