Solved

Array parse

Posted on 2008-06-09
5
163 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 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