Arrays

View: New views
6 Messages — Rating Filter:   Alert me  

Arrays

by bazD-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi folks

Im trying to do some stuff to an old farcry 3 custom admin tool that I
did a while back.

Basically, Ive got 2 x 1 dimensional arrays - lets call them
"listOne", and "listTwo"

listOne has about 1000 names inside
listTwo has a selection of 200 of those 1000 names

What Im trying to do is compare the two arrays, and create a 3rd array
"listThree" which is basically the result of removing items in listTwo
from listOne

To illustrate:

listOne = "andy, bob, jim, craig, steven"
listTwo = "bob,jim"

listThree ="andy,craig,steven"

Any idea on how I can go about doing this ?

Ive tried looping through and all sorts, but just havnt hacked it yet
(its monday,and Im still recovering from weekend celebrations!)

Thanks in advance
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "farcry-dev" group.
To post to this group, send email to farcry-dev@...
To unsubscribe from this group, send email to farcry-dev-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/farcry-dev?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Arrays

by Jake Churchill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


<cfloop from="1" to="#ArrayLen(listOne)#" step="1" index="i">
    <cfset itemFound = 0>
    <cfloop from="1" to="#ArrayLen(listTwo)#" step="1" index="j">
        <cfif listOne[i] eq listTwo[j]>
            <cfset itemFound = 1>
        </cfif>
    </cfloop>
    <cfif NOT itemFound>
        <cfset ArrayAppend(listThree,listOne[i])>
    </cfif>
</cfloop>

Jake Churchill
CF Webtools
11204 Davenport, Ste. 100
Omaha, NE  68154
http://www.cfwebtools.com
402-408-3733 x103



BazD wrote:

> Hi folks
>
> Im trying to do some stuff to an old farcry 3 custom admin tool that I
> did a while back.
>
> Basically, Ive got 2 x 1 dimensional arrays - lets call them
> "listOne", and "listTwo"
>
> listOne has about 1000 names inside
> listTwo has a selection of 200 of those 1000 names
>
> What Im trying to do is compare the two arrays, and create a 3rd array
> "listThree" which is basically the result of removing items in listTwo
> from listOne
>
> To illustrate:
>
> listOne = "andy, bob, jim, craig, steven"
> listTwo = "bob,jim"
>
> listThree ="andy,craig,steven"
>
> Any idea on how I can go about doing this ?
>
> Ive tried looping through and all sorts, but just havnt hacked it yet
> (its monday,and Im still recovering from weekend celebrations!)
>
> Thanks in advance
> >
>  


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "farcry-dev" group.
To post to this group, send email to farcry-dev@...
To unsubscribe from this group, send email to farcry-dev-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/farcry-dev?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Arrays

by Jeff Coughlin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> Im trying to do some stuff to an old farcry 3 custom admin tool that I
> did a while back.
>
> Basically, Ive got 2 x 1 dimensional arrays - lets call them
> "listOne", and "listTwo"
>
> listOne has about 1000 names inside
> listTwo has a selection of 200 of those 1000 names
>
> What Im trying to do is compare the two arrays, and create a 3rd array
> "listThree" which is basically the result of removing items in listTwo
> from listOne
>
> To illustrate:
>
> listOne = "andy, bob, jim, craig, steven"
> listTwo = "bob,jim"
>
> listThree ="andy,craig,steven"
>
> Any idea on how I can go about doing this ?
>
> Ive tried looping through and all sorts, but just havnt hacked it yet
> (its monday,and Im still recovering from weekend celebrations!)


Baz,

I don't remember where I found this custom function, but for a while  
now I've been using a function called ListInListFind() (not written by  
me).  A quick Google search found a copy here: http://www.mximize.com/find-item-in-list2-from-list1-list-to-list-compare- 
  (maybe he is the original author).

I rewrote it a long time back to be a cffunction (below).  Hope this  
helps!  (note: You may or may-not want to change the listFindNoCase to  
case sensitive).

=======
<cffunction name="listInListFind" returntype="string" access="public"  
output="false" hint="Returns the first match found in list1 compared  
to list2. Returns 0 if no match.">
   <cfargument name="list1" type="string" hint="A list"  
required="true" />
   <cfargument name="list2" type="string" hint="A list"  
required="true" />
   <cfargument name="delimiters" type="String" hint="Delimiter(s) used  
for the lists." required="false" default="," />

   <cfset var i = '' />
   <cfset var returnVar = 0 />

   <cfloop index="i" list="#arguments.list1#"  
delimiters="#arguments.delimiters#">
     <cfif listFindNoCase(arguments.list2, i, arguments.delimiters)>
       <cfset returnVar = i />
       <cfbreak />
     </cfif>
   </cfloop>

   <cfreturn returnVar />
</cffunction>
=======

Regards,

--
Jeff Coughlin
Web Application Developer
http://jeffcoughlin.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "farcry-dev" group.
To post to this group, send email to farcry-dev@...
To unsubscribe from this group, send email to farcry-dev-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/farcry-dev?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Arrays

by Jake Churchill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Baz,

I received your response off list and tried to reply but got a mailbox unavailable error.  So, here's my response... sorry rest of the list:

--- START OF RESPONSE ---

It's working for me.  Here's the code (I used your examples and added a couple dumps but the looping is the same):

<cfset listOne = ListToArray("andy,bob,jim,craig,steven")>
<cfset listTwo = ListToArray("bob,jim")>
<cfset listThree = ArrayNew(1)>

<cfdump var="#listOne#">
<cfdump var="#listTwo#">

<cfloop from="1" to="#ArrayLen(listOne)#" step="1" index="i">
    <cfset itemFound = 0>
    <cfloop from="1" to="#ArrayLen(listTwo)#" step="1" index="j">
        <cfif listOne[i] eq listTwo[j]>
            <cfset itemFound = 1>
        </cfif>
    </cfloop>
    <cfif NOT itemFound>
        <cfset ArrayAppend(listThree,listOne[i])>
        <cfoutput>Adding: #listOne[i]#<br /></cfoutput>
    </cfif>
</cfloop>

<h3>Here are the contents of listThree:</h3>
<cfdump var="#listThree#">

I set up a test page for you to view the results:  http://bryanlghgiftshop.cfwebtools.com/jake.cfm

--- END OF RESPONSE ---
Jake Churchill
CF Webtools
11204 Davenport, Ste. 100
Omaha, NE  68154
http://www.cfwebtools.com
402-408-3733 x103


Jeff Coughlin wrote:
Im trying to do some stuff to an old farcry 3 custom admin tool that I
did a while back.

Basically, Ive got 2 x 1 dimensional arrays - lets call them
"listOne", and "listTwo"

listOne has about 1000 names inside
listTwo has a selection of 200 of those 1000 names

What Im trying to do is compare the two arrays, and create a 3rd array
"listThree" which is basically the result of removing items in listTwo
from listOne

To illustrate:

listOne = "andy, bob, jim, craig, steven"
listTwo = "bob,jim"

listThree ="andy,craig,steven"

Any idea on how I can go about doing this ?

Ive tried looping through and all sorts, but just havnt hacked it yet
(its monday,and Im still recovering from weekend celebrations!)
    


Baz,

I don't remember where I found this custom function, but for a while  
now I've been using a function called ListInListFind() (not written by  
me).  A quick Google search found a copy here: http://www.mximize.com/find-item-in-list2-from-list1-list-to-list-compare- 
  (maybe he is the original author).

I rewrote it a long time back to be a cffunction (below).  Hope this  
helps!  (note: You may or may-not want to change the listFindNoCase to  
case sensitive).

=======
<cffunction name="listInListFind" returntype="string" access="public"  
output="false" hint="Returns the first match found in list1 compared  
to list2. Returns 0 if no match.">
   <cfargument name="list1" type="string" hint="A list"  
required="true" />
   <cfargument name="list2" type="string" hint="A list"  
required="true" />
   <cfargument name="delimiters" type="String" hint="Delimiter(s) used  
for the lists." required="false" default="," />

   <cfset var i = '' />
   <cfset var returnVar = 0 />

   <cfloop index="i" list="#arguments.list1#"  
delimiters="#arguments.delimiters#">
     <cfif listFindNoCase(arguments.list2, i, arguments.delimiters)>
       <cfset returnVar = i />
       <cfbreak />
     </cfif>
   </cfloop>

   <cfreturn returnVar />
</cffunction>
=======

Regards,

--
Jeff Coughlin
Web Application Developer
http://jeffcoughlin.com


  

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "farcry-dev" group.
To post to this group, send email to farcry-dev@...
To unsubscribe from this group, send email to farcry-dev-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/farcry-dev?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Arrays

by David Whiterod :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi Baz,

For a third option, you could try the arrayDiff UDF from
http://cflib.org/udf.cfm?ID=1572

cheers

David

On Jun 3, 12:46 am, BazD <cfmx...@...> wrote:

> Hi folks
>
> Im trying to do some stuff to an old farcry 3 custom admin tool that I
> did a while back.
>
> Basically, Ive got 2 x 1 dimensional arrays - lets call them
> "listOne", and "listTwo"
>
> listOne has about 1000 names inside
> listTwo has a selection of 200 of those 1000 names
>
> What Im trying to do is compare the two arrays, and create a 3rd array
> "listThree" which is basically the result of removing items in listTwo
> from listOne
>
> To illustrate:
>
> listOne = "andy, bob, jim, craig, steven"
> listTwo = "bob,jim"
>
> listThree ="andy,craig,steven"
>
> Any idea on how I can go about doing this ?
>
> Ive tried looping through and all sorts, but just havnt hacked it yet
> (its monday,and Im still recovering from weekend celebrations!)
>
> Thanks in advance
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "farcry-dev" group.
To post to this group, send email to farcry-dev@...
To unsubscribe from this group, send email to farcry-dev-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/farcry-dev?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Arrays

by bazD-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thanks everyone for your help.

Ive managed to sort out my problem in the end.

My problem was that if I hard coded 2 arrays, everyones ideas worked
fine, but If I tried to populate one of the arrays by pulling
information from a database, the ideas didnt work. Not sure why that
was, but anyway, Ive worked around it now.

Thanks again. B

On Jun 3, 1:49 am, David Whiterod <davidwhite...@...> wrote:

> Hi Baz,
>
> For a third option, you could try the arrayDiff UDF fromhttp://cflib.org/udf.cfm?ID=1572
>
> cheers
>
> David
>
> On Jun 3, 12:46 am, BazD <cfmx...@...> wrote:
>
> > Hi folks
>
> > Im trying to do some stuff to an old farcry 3 custom admin tool that I
> > did a while back.
>
> > Basically, Ive got 2 x 1 dimensional arrays - lets call them
> > "listOne", and "listTwo"
>
> > listOne has about 1000 names inside
> > listTwo has a selection of 200 of those 1000 names
>
> > What Im trying to do is compare the two arrays, and create a 3rd array
> > "listThree" which is basically the result of removing items in listTwo
> > from listOne
>
> > To illustrate:
>
> > listOne = "andy, bob, jim, craig, steven"
> > listTwo = "bob,jim"
>
> > listThree ="andy,craig,steven"
>
> > Any idea on how I can go about doing this ?
>
> > Ive tried looping through and all sorts, but just havnt hacked it yet
> > (its monday,and Im still recovering from weekend celebrations!)
>
> > Thanks in advance
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "farcry-dev" group.
To post to this group, send email to farcry-dev@...
To unsubscribe from this group, send email to farcry-dev-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/farcry-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

LightInTheBox - Buy quality products at wholesale price