Utility Functions: Three String Functions

Here is a trio of functions based on a question from Hal Helm's "Are you OO Ready" quiz, in which he mentions that you can do the following:

<cfset x = "something" />
<cfset y = x />
<cfoutput>#y.equals(x)#</cfoutput>

So I came up with these:

<cffunction name="StringToChars" access="public" output="false" returntype="array">
    <cfargument name="string" type="string" required="true" />
    
    <cfreturn arguments.string.toCharArray() />
</cffunction>

<cffunction name="StringEndsWith" access="public" output="false" returntype="boolean">
    <cfargument name="string" type="string" required="true" />
    <cfargument name="suffix" type="string" required="true" />
    
    <cfreturn arguments.string.endsWith(arguments.suffix) />
</cffunction>

<cffunction name="StringBeginsWith" access="public" output="false" returntype="boolean">
    <cfargument name="string" type="string" required="true" />
    <cfargument name="prefix" type="string" required="true" />
    
    <cfreturn arguments.string.startsWith(arguments.prefix) />
</cffunction>

 
Comments are not allowed for this entry.
Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me on LinkedIn.