Skip to main content
Inspiring
April 27, 2010
Answered

comma separated list - retrieving each item into an array ?

  • April 27, 2010
  • 1 reply
  • 421 views

Is there a quick way to take a field that contains a list of items separated by commas and putting them into an array or perhaps separate variables ?

eg.

a single row in the database contains the field [matches_with] and would typically contain the following:

rings, bracelets, necklaces

I need to either put each into a variable

<cfset item1='rings'>

<cfset item2='bracelets'>

<cfset item3=necklaces'>

or if its simpler, put them into an array

item[1]='rings'

item[2]='bracelets'

item[3]='necklaces'

This topic has been closed for replies.
Correct answer JR__Bob__Dobbs-qSBHQ2

There is a ListToArray function built in to CF.

1 reply

JR__Bob__Dobbs-qSBHQ2Correct answer
Inspiring
April 27, 2010

There is a ListToArray function built in to CF.

Inspiring
April 27, 2010

Thanks JR - fantastic!

I'm reading O'Reilly's Programming Coldfusion and looking through "Finding Strings" and there's no mention of it. Off to look on the web. It sounds exactly what I need!