• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

How to parse a string?

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?
0
futureman
Asked:
futureman
2 Solutions
 
mkishlineCommented:
<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>
0
 
gdemariaCommented:
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, "|")>
0
 
futuremanAuthor Commented:
Thanks.   That was exactly what I was looking for.
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now