A couple of basic string parsing functions I have an app that does a fair bit of text-parsing based on free-form user inputs.  In this, I run searches on the whole string, and then on the last value of the string separate from the rest of the string.  Here is a pair of functions I wrote to getLast and getSubString.

&lt;cffunction name="getLast" output="no" returnType="string" access="public" hint="Takes a string and returns the last value by either comma or space, or returns nothing if the string is only one value long"&gt;
    &lt;cfargument name="str" required="yes" type="string"&gt;

    &lt;cfset var returnVar = ""&gt;

    &lt;cfif listLen(arguments.str) GT 1&gt;
        &lt;cfoutput&gt;listLen(#arguments.str#)&lt;/cfoutput&gt;
        &lt;cfset returnVar = trim(listLast(arguments.str))&gt;
    &lt;cfelseif listLen(arguments.str, " ") GT 1&gt;
        &lt;cfoutput&gt;listLen(#arguments.str#, " ")&lt;/cfoutput&gt;
        &lt;cfset returnVar = trim(listLast(arguments.str, " "))&gt;
    &lt;/cfif&gt;

    &lt;cfreturn returnVar&gt;
&lt;/cffunction&gt;

&lt;cffunction name="getSubString" output="no" returnType="string" access="public" hint="Takes a string and returns the beginning of the string minus the last value"&gt;
    &lt;cfargument name="str" required="yes" type="string"&gt;

    &lt;cfset var last = getLast(arguments.str)&gt;
    &lt;cfset var lastLen = len(last) + 1&gt;
    &lt;cfset var thisLen = len(str) - lastLen&gt;
    &lt;cfset var returnVar = str&gt;

    &lt;cfif thisLen GTE 1&gt;
        &lt;cfset returnVar = trim(mid(str, 1, thisLen))&gt;
    &lt;/cfif&gt;

    &lt;!--- remove trailing commas ---&gt;
    &lt;cfif right(trim(returnVar), 1) IS ","&gt;
        &lt;cfset returnVar = mid(returnVar, 1, len(trim(returnVar)) - 1)&gt;
    &lt;/cfif&gt;

    &lt;cfreturn returnVar&gt;
&lt;/cffunction&gt;


And just for fun, some code that was commented out of the second function:

&lt;!---
&lt;cfset var listDelim = ","&gt;
&lt;cfset var i = 0&gt;
&lt;cfset var returnVar = ""&gt;

&lt;!--- if the string is longer than one value ---&gt;
&lt;cfif len(last)&gt;
    &lt;cfif NOT findNoCase(arguments.str, ",")&gt;
        &lt;cfset listDelim = " "&gt;
    &lt;/cfif&gt;
    &lt;cfloop from="1" to="#evaluate(listLen(arguments.str, listDelim) - 1)#" index="i"&gt;
        &lt;cfset returnVar = "#returnVar# #listGetAt(arguments.str, i, listDelim)#"&gt;
    &lt;/cfloop&gt;
    &lt;cfset returnVar = trim(returnVar)&gt;
&lt;cfelse&gt;
    &lt;cfset returnVar = arguments.str&gt;
&lt;/cfif&gt;
---&gt;


Next time I think I'm going to avoid parsing all my own text and just dumping it all into SOLR.
If you are using ColdFusion 9+, you should abandon your vars within functions and move toward using the LOCAL scope.  LOCAL vars do not escape the function.

This:

&lt;cfset var last = getLast(arguments.str)&gt;
&lt;cfset var lastLen = len(last) + 1&gt;
&lt;cfset var thisLen = len(str) - lastLen&gt;
&lt;cfset var returnVar = str&gt;


Should be:

&lt;cfset LOCAL.last = getLast(arguments.str)&gt;
&lt;cfset LOCAL.lastLen = len(LOCAL.last) + 1&gt;
&lt;cfset LOCAL.thisLen = len(LOCAL.str) - LOCAL.lastLen&gt;
&lt;cfset LOCAL.returnVar = str&gt;