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

how to get the first character of a string

Status
Not open for further replies.

olmos

Technical User
Oct 25, 2000
135
US
How do I get the first character out of a string? For example,
John Doe, J. I am looking for a way to just get the initials out of a name.

Thanks in advance,
olmos
 
What format does the name have? Could you have first last, first middle last, first middle last honorific, etc., in the same field/variable?

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'll have the roast duck with the mango salsa.
 
It will only have the format of first and last name.

Thanks,
olmos
 
<cfset myfield = "Joe Coderman">
<cfset initials = "">
<Cfloop index="name" list="#myfield#" delimiters=" ">
<cfset initials = initials & left(name,1)>
</cfloop>


<cfoutput>#initials#</cfoutput>

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'll have the roast duck with the mango salsa.
 
Thanks, this worked.

olmos
 
That's good. If the name's coming out of a database, I'd prefer to use database string functions to return the initials. YMMV depending on your database engine flavor.

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'll have the roast duck with the mango salsa.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top