Skip to main content
Participant
October 12, 2010
Answered

Help with number to array

  • October 12, 2010
  • 6 replies
  • 654 views

I would like to take a number such as "12345" and turn it into a list or array such as "1,2,3,4,5". I am using this for my hit counter. I am able to return the value out of a database but would like each individual number to correspond to an image file.

PLEASE HELP

    This topic is closed to new replies. Start a new post to keep the conversation going.
    Correct answer

    Does it have to be an array?

    You can easily loop around the length of the string, and then extract that character for your number file.

    <cfloop from="1" to="#Len('12345')#" index="i">

         <cfset numInFocus = Mid('12345', i, 1)>

         ... process loading image ... 

    </cfloop>

    Dave @ Oyova Software

    http://www.oyova.com - Web Design and Development

    6 replies

    ilssac
    Inspiring
    October 12, 2010

    I thought I heard once that one can create a character array by using a list function with no delimiter.

    <cfset charArray = listToArray("12345","")>

    <cfdump var="#charArray#">

    Untested, but may be worth a try.

    Inspiring
    October 12, 2010
    <cfset charArray = listToArray("12345","")>
    <cfdump var="#charArray#">
    

    Hi Ian

    That doesn't work on CF8, but it perhaps works on CF9 (I don't have a CF9 box here).

    However this does work on CF8:

    <cfset charArray = listToArray(reReplace("12345","(.)", "\1,", "ALL"))>

    That said, the posting above marked as "the answer" is as good as any.

    --

    Adam

    Inspiring
    October 12, 2010

    However this does work on CF8:

    <cfset charArray = listToArray(reReplace("12345","(.)",

    "\1,", "ALL"))>

    Haha. Sneaky.

    -Leigh

    Correct answer
    October 12, 2010

    Does it have to be an array?

    You can easily loop around the length of the string, and then extract that character for your number file.

    <cfloop from="1" to="#Len('12345')#" index="i">

         <cfset numInFocus = Mid('12345', i, 1)>

         ... process loading image ... 

    </cfloop>

    Dave @ Oyova Software

    http://www.oyova.com - Web Design and Development

    hello1974Author
    Participant
    October 12, 2010

    Thanx. That worked perfect. Using this forum was alot faster than searching around on GOOGLE.