Jump to content
Sign in to follow this  
wutzke

array logic

Recommended Posts

wutzke

if you have an array with:

$ararry1[1]="070105|5"

$ararry1[2]="080105|5"

$ararry1[3]=""

$ararry1[4]="100105|5"

$ararry1[5]=""

and a second array with:

$arrary2[1]="070105|"

$arrary2[2]="080105|"

$arrary2[3]="090105|"

$arrary2[4]="100105|"

$arrary2[5]="110105|"

how could you change the second array to:

$arrary2[1]="070105|5"

$arrary2[2]="080105|5"

$arrary2[3]="090105|"

$arrary2[4]="100105|5"

$arrary2[5]="110105|"

for $i = 1 to unbound($array2)

if len($arrray2[$i] >7 then

$arrray2[$i] =$arrray1[$i]

endif

next

Share this post


Link to post
Share on other sites
/dev/null

how could you change the second array to:

$arrary2[1]="070105|5"

$arrary2[2]="080105|5"

$arrary2[3]="090105|"

$arrary2[4]="100105|5"

$arrary2[5]="110105|"

like this?

$arrary2[1]="070105|5"
$arrary2[2]="080105|5"
$arrary2[3]="090105|"
$arrary2[4]="100105|5"
$arrary2[5]="110105|"

seriously, without a "pattern" for the change, nobody can tell you how to do it!

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites
seandisanti

like this?

$arrary2[1]="070105|5"
$arrary2[2]="080105|5"
$arrary2[3]="090105|"
$arrary2[4]="100105|5"
$arrary2[5]="110105|"
oÝ÷ ÚÇ«¬,"¶.µª®¢ÚZ¶×««¨µú+¶©àzz¡Üj{^¨º0¶hÝ÷
®Â®®ßêº^Éë"Á« ¢)à¶É¶¬yÚ'¶¢ú+«b¢x"½éâß×cºË`£­«­¢+Ø(ÀÌØíÉÉÉäÉlÅtôÅÕ½ÐìÀÜÀÄÀÕðÔÅÕ½Ðì(ÀÌØíÉÉÉäÉlÉtôÅÕ½ÐìÀàÀÄÀÕðÔÅÕ½Ðì(ÀÌØíÉÉÉäÉlÍtôÅÕ½ÐìÀäÀÄÀÕðÅÕ½Ðì(ÀÌØíÉÉÉäÉlÑtôÅÕ½ÐìÄÀÀÄÀÕðÔÅÕ½Ðì(ÀÌØíÉÉÉäÉlÕtôÅÕ½ÐìÄÄÀÄÀÕðÅÕ½Ðì

Share this post


Link to post
Share on other sites
nikink

Well, the pattern would be something like if array1 is "" then array2 remains unchanged, else array2 should be set to array1

But I'm not great with arrays, so more help than that could be tricky...

Share this post


Link to post
Share on other sites
wutzke

the 1st array is the result of collecting data each month. some months have data (|5). some months don't have data and don't leave the date in the array. the second array is created and is a run of dates for a given period. I just want the show the complete run of dates in the array even if there is not data. sometimes the dates are not in order. so

$ararry1[1]="100105|5"

$ararry1[2]="080105|6"

$ararry1[3]=""

$ararry1[4]="070105|5"

$ararry1[5]=""

knowing that the start date is 07/01/05 and the end date is 11/01/05

$arrary2[1]="070105|"

$arrary2[2]="080105|"

$arrary2[3]="090105|"

$arrary2[4]="100105|"

$arrary2[5]="110105|"

i'd like to end up with

$arrary2[1]="070105|5"

$arrary2[2]="080105|5"

$arrary2[3]="090105|"

$arrary2[4]="100105|5"

$arrary2[5]="110105|"

Share this post


Link to post
Share on other sites
nikink

If array1 is not in order then that makes the comparison tricky.

Could you alter the array1 creator to put the date in even if there is no data?

If the array1 dates are going in randomly, perhaps an array sort first, then pad out the gaps between dates... but that's getting above my head at the moment!

Share this post


Link to post
Share on other sites
/dev/null

If array1 is not in order then that makes the comparison tricky.

not as tricky as you think...

The following code is NOT optimal. It contains more code than needed to do the job, but it hopefully helps you to understand!

#include <Array.au3>

dim $array1[6]
dim $array2[6]

$array1[1]="100105|5"
$array1[2]="080105|6"
$array1[3]="110105|8"
$array1[4]="070105|5"
$array1[5]=""

$array2[1]="070105|"
$array2[2]="080105|"
$array2[3]="090105|"
$array2[4]="100105|"
$array2[5]="110105|"

for $index1 = 1 to UBound($array1)-1
    $splitted1 = StringSplit($array1[$index1],"|")
    If $splitted1[0] > 1 Then
        $date1 = $splitted1[1]
        $value1 = $splitted1[2]
        for $index2 = 1 to UBound($array2)-1
            $splitted2 = StringSplit($array2[$index2],"|")
            If $splitted2[0] > 1 Then
                $date2 = $splitted2[1]
                if $date1 = $date2 Then
                    $array2[$index2] = $date2 & "|" & $value1
                endif
            EndIf
        Next
    EndIf
Next

_ArrayDisplay($array2,"Array2")

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.