String Tokenizer ColdFusion Component That Can Handle Qualified Fields

<!---
	First we have to set up the delimited value that we are
	going to pass in. In this case, I am going to use the
	comma as the delimiter and the quote as the field
	qualifier. Notice that the third value has embedded
	delimiters and qualifiers.
--->
<cfsavecontent variable="strCSV">
a,b,"cat,kitten,""mog"",puppy",d,e,"""",f
</cfsavecontent>
 
 
<!---
	Now, let's create the ColdFusion String Tokenizer. We are
	going to pass in the CSV value and the qualifier. We do not
	have to pass in the field delimiter or the qualifier as they
	default to comma and quote respectively.
--->
<cfset objTokenizer = CreateObject(
	"component",
	"StringTokenizer"
	).Init(
		String = strCSV.Trim()
	) />
 
 
<!---
	Now that we have the String Tokenizer, we can loop over it
	until it has no more elements / tokens to returns. Here I am
	demonstrating the "Elements" method call, but there is also
	a short-hand HasMoreTokens() method call that does the same
	thing. I only use Elements here because I feel it is more
	common to the Iterator interface.
--->
<cfloop condition="objTokenizer.HasMoreElements()">
 
	<!---
		Get the next token and output it. We are using the
		brackets to help clarify where certain values are blank.
	--->
	[#objTokenizer.NextElement()#]<br />
 
</cfloop>
 
 
<!---
	Now, in order to demonstrate that this Tokenizer can be
	re-used without calling CreateObject(), we are going to just
	re-Init() it and pass in new values... well actually, the
	same CSV, but this time, the field qualifier is being sent
	in as the empty string.
--->
<cfset objTokenizer.Init(
	String = strCSV.Trim(),
	Qualifier = ""
	) />
 
 
<!--- Now, as we did before, loop over the tokens. --->
<cfloop condition="objTokenizer.HasMoreElements()">
 
	[#objTokenizer.NextElement()#]<br />
 
</cfloop>

For Cut-and-Paste