CFLib.org – Common Function Library Project

celticMcCaps(lastName)

Last updated December 5, 2010

Version: 2 | Requires: ColdFusion 5 | Library: StrLib

 
Rated 5 time(s). Average Rating: 2.8

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:

view plain print about
<cfset last_name = "mcnamara">

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

Parameters:

Name Description Required
lastName String to modify. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * 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;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
4 day(s) ago

Will Belden Will Belden added
longTime
9 day(s) ago

James Sleeman James Sleeman added
quickSort
19 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
22 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson