Freeze128 Posted March 31, 2006 Posted March 31, 2006 I might be completely barking up the wrong tree here, so let me know if I am... I'm trying to populate a multidimensional array with values that are coming from one string. The values are separated by a delimiter (like just a pipe |). I started writing a function to count the delimiters, and every time it hits one, it increases the element number. If it hits 2 delims in a row, that means increase the number of dimensions. Well, it just occurred to me that I don't really know how I can programmatically redim an array with a number of dimensions that is stored in a variable. I mean, it's not like there is a function like: CreateArray($elements, $dimensions) The only reason I'm doing this is to populate a multidimensional array quickly with a static set of data. For example: red::fire blue::water white::wind green::earth I was trying to avoid doing it like: $array[1][1] = "red" $array[1][2] = "fire" $array[2][1] = "blue" $array[2][2] = "water" $array[3][1] = "white" ... Is there any way I can just stream it into an array with a variable like: $String="red|fire||blue|water||white|wind||green|earth"
Valuater Posted March 31, 2006 Posted March 31, 2006 sounds like stringsplit() $days = StringSplit("Sun,Mon,Tue,Wed,Thu,Fri,Sat", ",") ;$days[1]contains "Sun" ... $days[7] contains "Sat" see help 8)
blindwig Posted March 31, 2006 Posted March 31, 2006 (edited) The only reason I'm doing this is to populate a multidimensional array quickly with a static set of data. [...] Is there any way I can just stream it into an array with a variable like: $String="red|fire||blue|water||white|wind||green|earth"If you have the Beta version, try this: Dim $String[3][2]=[[red,fire],[blue,water],[white,wind],[green,earth]] look in the beta docs for the Dim function to get the syntax Edited March 31, 2006 by blindwig My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions
Freeze128 Posted April 1, 2006 Author Posted April 1, 2006 sounds like stringsplit()see help8)I did read up on StringSplit. While it's very clear how I could use that to populate a one dimensional array, I wasn't quite sure how I could use that to populate a multidimensional array. The help page makes no reference to anything other than a single dimension.You know, it's kinda funny, I almost used that exact same example above, but decided against it because the problem was too easy to solve with a 1 dimensional array.
Freeze128 Posted April 1, 2006 Author Posted April 1, 2006 If you have the Beta version, try this: Dim $String[3][2]=[[red,fire],[blue,water],[white,wind],[green,earth]] look in the beta docs for the Dim function to get the syntax Beautiful! While it isn't quite as flexible as reading it from a string, I think the above syntax will do nicely. Thanks a million!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now