How to parse a string?

futureman
futureman used Ask the Experts™
on
In Coldfusion, I need to parse a delimited string and put it into an array and then later loop through that array.

What is the easiest way to do that?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
<cfset arr = ArrayNew(1) />
<cfloop index="i" list="#delimitedstring#" delimiter="character_that_serves_as_delimiter">
  <cfset ArrayAppend(arr, i) />
</cfloop>

then to loop through the array later
<cfloop index="J" from="1" to="#ArrayLen(arr)#">
  #arr[j]#
</cfloop>
Use the function   "listToArray()"

 <cfset variables.myArray = listToArray(variables.myList)>

 If the list is not comma delimited, add the delimiter..

 Say the delimiter is the pipe  '|'

  <cfset variables.myArray = listToArray(variables.myList, "|")>

Author

Commented:
Thanks.   That was exactly what I was looking for.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial