CFLib.org – Common Function Library Project

celticMcCaps(lastName)

Last updated December 5, 2010

author

Kyle McNamara

Version: 2 | Requires: CF5 | Library: StrLib

Description:
You can use this function whenever you output an undetermined list of last names in order to be sure that the McNamaras and the MacGreggors names are output correctly.

Return Values:
Returns a string.

Example:

<cfset last_name = "mcnamara">

<cfoutput>
#celticMcCaps(last_name)#
</cfoutput>

Parameters:

Name Description Required
lastName String to modify. Yes

Full UDF Source:

/**
 * Proper capitalization for us Mc's and Mac's!
 * v2 by Kris Korsmo
 * 
 * @param lastName 	 String to modify. (Required)
 * @return Returns a string. 
 * @author Kyle McNamara (kyle@themacs.info) 
 * @version 2, December 5, 2010 
 */
function celticMcCaps(lastName) {
    var capLastName = lCase(lastName);
    if (left(lastName,2) eq "Mc") {
        capLastName = uCase(left(lastName,1)) & lCase(mid(lastName,2,1)) & uCase(mid(lastName,3,1)) & lCase(right(lastName,len(lastName)-3));
        return capLastName;
    }
    else if (left(lastName,3) eq "Mac") {
        capLastName = uCase(left(lastName,1)) & lCase(mid(lastName,2,1)) & lCase(mid(lastName,3,1)) & uCase(mid(lastName,4,1)) & lCase(right(lastName,len(lastName)-4));
        return capLastName;
    }
    else if (left(lastName,2) eq "O'") {
        capLastName = uCase(left(lastName,1)) & "'" & uCase(mid(lastName,3,1)) & lCase(right(lastName,len(lastName)-3));
        return capLastName;
    }
    else return lastName;
}
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