Solved

Array parse

Posted on 2008-06-09
5
164 Views
Last Modified: 2013-12-24
I have a variables set in a cookie. It can have a max of three variables, e.g. (17000,18234,21345)
I've tried to loop through them with no success. I need to loop through the cookie and pull each value out and assign the cookie name (CFID) and number to it. For example the first value would be CIDS1 and the second, CIDS2, etc.

<cfset arr = ArrayNew(1)>
<cfloop index="i" list="#CIDS#" delimiters=",">
  <cfset ArrayAppend(arr, i)>
</cfloop>
0
Comment
Question by:usky1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:usky1
ID: 21746545
I forgot to add the rest of the loop,
<cfloop index="j" from="1" to="#ArrayLen(arr)#">
 <cfoutput> #arr[j]# </cfoutput>
</cfloop>
0
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 21751264
I guess I don't quite get what you are trying to do (not that it's that important that I understand)
1) you have one cookie whose value is a comma delimited list - correct?
2) you want to loop through this value and create new variables for each one - is that correct?

something like this?
<cfset cids="123,456,789">
<cfset counter=0>
<cfloop index="i" list="#CIDS#" delimiters=",">
<cfset counter=counter+1>
      <cfset "CIDS#counter#"=i>
</cfloop>
<cfloop index="j" from="1" to="#counter#">
<cfoutput>#variables["CIDS" & j]#</cfoutput><br>
</cfloop>

if this isn't close please provide info as to what you want to do in the end - i.e. the concept
0
 

Author Comment

by:usky1
ID: 21751704
1) you have one cookie whose value is a comma delimited list - correct? yes
2) you want to loop through this value and create new variables for each one - is that correct? yes
Sorry for the question confusion. I need to loop through each cookie value and create a new one. For example,
If the cookies first value is 123 I need to do a <cfset number1 = 123>
If the second is 456 then <<cfset number2 = 456>
There are not always three values, there might not even be any depending on previous functions.
How can I loop through and add the cfsets, if existing?
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 21751847
see the code i posted above
this will loop and set the number of vars that you have in your list
if you have  a list of 2 then 2 vars will be set
if you have 5 then 5 will be set
try it out ...

note that the last cfloop in my example is not part of the code but just a way for you to see what has been set
0
 

Author Comment

by:usky1
ID: 21752089
Works great. thanks for your help.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question