CFLib.org – Common Function Library Project

getNameInitials(str)

Last updated October 4, 2007

author

Anonymous

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Creates a sequence of initials based on an input name string. The UDF essentially takes the first characters of each word in the input string, capitalizes them and puts them together.

Return Values:
Returns a string.

Example:

<cfset name="John Alexander Smith"><br>
<cfoutput>Initials for #name# are #getNameInitials(name)#</cfoutput>

Parameters:

Name Description Required
str String to parse. Yes

Full UDF Source:

/**
 * Extracts the initials of a name from long string.
 * 
 * @param str 	 String to parse. (Required)
 * @return Returns a string. 
 * @author Anonymous (anonymous@gmail.com) 
 * @version 1, October 4, 2007 
 */
function getNameInitials(str) {
	var newstr = "";
	var word = "";
	var i = 1;
	var strlen = listlen(str," ");
	for(i=1;i lte strlen;i=i+1) {
		word = ListGetAt(str,i," ");
		newstr = newstr & UCase(Left(word,1));
	}
	return newstr;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson