Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help with number to array

New Here ,
Oct 12, 2010 Oct 12, 2010

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

660
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Oct 12, 2010 Oct 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

Translate
Guest
Oct 12, 2010 Oct 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 12, 2010 Oct 12, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 12, 2010 Oct 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 12, 2010 Oct 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 12, 2010 Oct 12, 2010
LATEST

However this does work on CF8:

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

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

Haha. Sneaky.

-Leigh

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 12, 2010 Oct 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","")>

Yep. I would have to double check it, but ... I believe that works in CF9 only.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources