?
Solved

Array parse

Posted on 2008-06-09
5
Medium Priority
?
166 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 2000 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month10 days, 17 hours left to enroll

770 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