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

Detecting a space, placing variables in text boxes

Status
Not open for further replies.

programmher

Programmer
May 25, 2000
235
0
0
US
I have a database with names in one field - FullName.

How can I detect the space, put everything to the left of the space in field FirstName and everything right of the space in field LastName?

Ex: John Doe should be in two separate fields instead of one field.
Ex: Lucille MacGillicuddy should be in two separate fields instead of one field
 
THIS is only for those individuals with common names.....
firstname lastname

<cfset firstName=listFirst(FullName, &quot; &quot;)>
<cfset lastName=listLast(FullName, &quot; &quot;)>

------------------------------------------------------------------------------
brannonH
if( !succeed ) try( );
 
brannon,

Thanks a million!!! This worked like a charm!! One last question - is there a way to capture middle names or middle initials? <cfset midName=listMid(fullname, &quot;&quot;)> and <cfset middleName=listMiddle(Fullname, &quot;&quot;)> did not work.
 
List first and last give you the first item and last item of a list. The list being first name, middle name, last name each seperated with a space.

You should first find out how many names are listed in the box:
<cfset nameCount=ListLen(FullName, &quot; &quot;)>

Now you can set one, two or three variabales accordingly.

<cfif nameCount EQ 3>
<cfset firstName=listFirst(FullName, &quot; &quot;)>
<cfset middleName=listGetAt(FullName, 2, &quot; &quot;)>
<cfset lastName=listLast(FullName, &quot; &quot;)>
<cfelse>
<cfset firstName=listFirst(FullName, &quot; &quot;)>
<cfset lastName=listLast(FullName, &quot; &quot;)>
</cfif>

This assuming there are two or three names and not 4 or 5.

DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
You might for your sake run on 4 for the sake of suffixes, jr, sr, etc... which of course follows the same line of code as deziner's

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top