Sign in to follow this  
Followers 0
schmidt2

splitting an array into two ones

6 posts in this topic

hello guys, i am a newbie who got stuck with maybe an very easy thing.(?)

i've got an ini file and need to get 2 groups of section names put into two different arrays.

example:

[a_something_else]
...
[section_1]
...
[section_2]
...
[another_something_else]
..
[extension_1]
...
[extension_2]
...

first i got all the section titles with "IniReadSectionNames". as the wanted names are "section_x" and "extension_x" i used an "_ArraySort" and "_ArrayDelete" to get rid of the [a_something_else] and [another_something_else] section names.

! this works in my special case as those always start with an "a" (they are on top of the array after sorting it) and i know how much of them are in the ini file (so even an _ArrayDelete works here).

but now i do not get the point how to split the remaining array into two ones, as the number of the section names [section_x] and [extension_x] varies every time:

array_1[0]=extension_1
array_1[1]=extension_2
array_1[x]=extension_x
array_1[x+1]=section_1
array_1[x+2]=section_2
array_1[x+x]=section_x

that is how my array looks like know but i need something like this:

;first array
array_1[0]=extension_1
array_1[1]=extension_2
array_1[x]=extension_x
;and second one
array_2[1]=section_1
array_2[2]=section_2
array_2[x]=section_x

i'm sure there is an easy solution and it's only me, the newbie not to see the wood for the trees? :">

thanks in advance for your help :whistle:

Share this post


Link to post
Share on other sites



To me the easiest solution seems to get the total number of sections, for instance by UBound (after you got rid of the junk ofcourse), divide it by two, and doing two for-loops to read them in. If you want them in two different array names that is. You might also want to consider double-dimensioned arrays, like Dim $array[x][2] (two elements for every x).


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

thanks for your fast reply but i should mention that the amount of the [extension_x] and [section_x] section names aren't always equal.

for example there might be 2 "extension" ones and 10 with the "section" section name.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Got it after i hit the hay, and it was really easy. :">

Maybe there are some other newbies around who will come up with the same question so here is my solution how i solved my problem:

IniReadSectionNames () ; getting all the section names
_ArraySort () ; you do not really need this (but both new arrays you'll get below are than already sorted)
_ArrayToString () ; putting the array into an string (as i found no option to do an RegExp search in arrays)
StringRegExp () ; searching for "section_x" and putting it into an array
StringRegExp () ; searching for "extension_x" and putting it into an array

Voila, there are to new arrays each containing either all "section_x" or all "extension_x" names. :whistle:

Edited by schmidt2

Share this post


Link to post
Share on other sites

Got it after i hit the hay, and it was really easy. :">

Maybe there are some other newbies around who will come up with the same question so here is my solution how i solved my problem:

IniReadSectionNames () ; getting all the section names
_ArrayToString () ; putting the array into an string (as i found no option to do an RegExp search in arrays)
:">

Look for _StringBetween in the UDFs3 help file.

You'll find a switch $iSRE refering to regular expression search of an array.

Share this post


Link to post
Share on other sites

Thanks for your tip. :whistle:

:">

Look for _StringBetween in the UDFs3 help file.

You'll find a switch $iSRE refering to regular expression search of an array.

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  
Followers 0