Sign in to follow this  
Followers 0
Tvern

Multidimensional array to string and back

9 posts in this topic

Because I get far to little use out of Execute() and recursion, I was inspired to write these functions by This post. (I actually though I might be able to use Assign and Eval too)

The purpose of the functions is mainly to allow saving multi dimensional arrays to a file, for later use.

I quickly found that the recursion level of my brain was exceeded and got pretty confused while writing this, so if you find a way to improve it, be my guest.

Solutions around the mad switch statement are especially welcome.

_ArrayEx.au3

Share this post


Link to post
Share on other sites



Solutions around the mad switch statement are especially welcome.

That would probably need some Dev involvement as there is no known other way. (Array create function. (Any dimension) (test case)(Alternatives are welcome.))

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

I was afraid of that. I can't imagine it being a very high priority either, as arrays with more than ~4 dimension are not something that's people use often. (or at all)

I don't even know if anyone will have a use for these functions because of that. But thought I'd post em just to be sure.

When you start writing scripts to write statements you know something isn't right though.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I just tested _ArrayToStringEx on the 2D array I wrote in this topic. I was kind of expecting to get an AutoIt syntax string, including square brackets. Perhaps it's an idea!

I thought the above topic may be interesting because the array I mentioned is a different kind of beast. Each element contains another 2D array represented as a string. You might think that it would therefore be a 4D array, but strictly speaking that isn't true. Or is it? ;)

Edited by czardas

Share this post


Link to post
Share on other sites

I just tested _ArrayToStringEx on the 2D array I wrote in this topic. I was kind of expecting to get an AutoIt syntax string, including square brackets. Perhaps it's an idea!

Before this version I made a version that would save any array as xml, but I didn't like a opening and closing tag for each dimension. It caused allot of overhead if your last dimension is small.

I could probably modify it to produce an autoit style in-line array declaration.

I thought the above topic may be interesting because the array I mentioned is a different kind of beast. Each element contains another 2D array represented as a string. You might think that it would therefore be a 4D array, but strictly speaking that isn't true. Or is it? ;)

I was thinking about adding variable type support and had some idea's on how to do it.

Including an array as a valid variable type would also be possible if you convert the array to a string again using the function. And the arrays in that array etc...

It would mean that the recursion level could be exceeded if someone creates a stack of 30 64d arrays though. :)

When I need some distraction again I'll take another look. (Usually doesn't take long)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I find it interesting: because it often seems more convenient to parse a string, rather than modify an array; at least in certain cases. I'll keep my eye on this topic. ;)

Edit

The tic-tac-toe example, I mentioned, is designed to quickly find grid positions by searching for matching strings. Having to match individual array elements (of each grid) would be rather slow by comparison.

Edited by czardas

Share this post


Link to post
Share on other sites

I think I see what you mean, but I'm not sure how to create something like this that would effeciently let you search the entire string for matching elements and then get the rest of the substring (array representation) that element belongs to.

It won't be too hard to make something that does that, but it probably won't be pretty.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

The case above is only one instance where I consider the string representation to have an advantage over an array. I'm actaully refering to matching a whole array (or grid), and not individual elements. However with regexp many things are possible.

I haven't thought too deeply about a general case. I was however thinking that using standard array declaration syntax would be convenient way to structure the string. There may be some complications with single or double quotes (if they occur within an array of strings), but I imagine that using Chr(34) and Chr(39) would solve these issues. Like you said, it could get messy, especially with 64 dimensions. Still it's something to think about. :graduated:

Edit

The arrayToString function would have to recognize data types, which adds a little more complication. I need to think about this.

Edited by czardas

Share this post


Link to post
Share on other sites

Here is link to my 2D only solution:

Func _ArrayToString2D(Const ByRef $avArray, $sDelimCol = "|", $sDelimRow = @CRLF, $iStart = 0, $iEnd = 0) 

Func _ArrayToHtml2D(Const ByRef $avArray, $attrib = 'border="1"', $iStart = 0, $iEnd = 0) 

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