Utility Functions: Three String Functions
- January 16, 2009 2:32 PM
- Utility Function
- Comments (0)
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>
<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>
<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>