camelToSpace(str [, capitalize])
Last updated March 8, 2010
Version: 0 | Requires: ColdFusion MX | Library: StrLib
Description:
This is not about furry puppets in a rocket ship, but a function that takes a camel cased string and returns it lower-cased with spaces between the words. Comes in handy if you want to generate human readable captions from (camel cased) table column names.
Return Values:
Returns a string
Example:
<cfset str='aCamelCasedVariable'>
#camelToSpace(str,true)#
<br/>
#camelToSpace(str)#
</cfoutput>
a very fancy column name
id column
Parameters:
| Name | Description | Required |
|---|---|---|
| str | String to use | Yes |
| capitalize | Boolean to return capitalized words | No |
Full UDF Source:
<cfscript>
/**
* Breaks a camelCased string into separate words
* 8-mar-2010 added option to capitalize parsed words Brian Meloche brianmeloche@gmail.com
*
* @param str String to use (Required)
* @param capitalize Boolean to return capitalized words (Optional)
* @return Returns a string
* @author Richard (brianmeloche@gmail.comacdhirr@trilobiet.nl)
* @version 0, March 8, 2010
*/
function camelToSpace(str) {
var rtnStr=lcase(reReplace(arguments.str,"([A-Z])([a-z])"," \1\2","ALL"));
if (arrayLen(arguments) GT 1 AND arguments[2] EQ true) {
rtnStr=reReplace(arguments.str,"([a-z])([A-Z])","\1 \2","ALL");
rtnStr=uCase(left(rtnStr,1)) & right(rtnStr,len(rtnStr)-1);
}
return trim(rtnStr);
}
</cfscript>
Search CFLib.org
Latest Additions
Shawn Porter added
DeMoronize
3 hour(s) ago
Chris Carey added
readPropertiesFi...
1 day(s) ago
Randy Johnson added
lastDayofWeek
3 day(s) ago
Frank Marion added
sitemapPing
7 day(s) ago
Top Rated
QuickSort
Rated 5.0, 3 time(s)
indentXml
Rated 5.0, 3 time(s)
queryColumnsToSt...
Rated 5.0, 3 time(s)
generateSsccAsn
Rated 5.0, 3 time(s)