Sign in to follow this  
Followers 0
markyrocks

How do i turn an array of strings into 2d array of letters?

4 posts in this topic

#1 ·  Posted (edited)

As the topic states I'm trying to turn an array of strings into a 2d array of letters and its giving me fits for some reason.  I have searched around couldn't really find a solid answer.  Seems like what i'm doing should work but for whatever reason it doesn't.  I've tried it multiple ways and keep getting errors.  Please just look it over and tell me what you think.

        

$t = 1
$s = 1
$x = 1
Dim $array[30]
dim $array1[30][30]

while $x <> $numberofchoices
$array = StringSplit($ch[$x],"")           

Do

$array1[$t][$s] = $array[$s]

$s = $s + 1

Until $s = $letters
$t = $t + 1
$x = $x + 1


WEnd
 
The point of this is im making a program that you enter in a list of words like 10 words and it then compares the letter placements that are common with the word like' bed' and 'bat' have one letter in common in the same slot but "bed" and "tab" have 0 in common.
eventually i may turn it into a small word guessing game kinda thing.  I know it sounds dumb but i got to learn somehow.
 
and ofcourse this is just a snipit of the whole program so the other variables are declared and assigned data further up in the code.
ok so ty in advance.
 
Also I've tested the variable $ch[$x] further up in the program to see if its saving the wordlist correctly and it seems to work just fine.
Edited by markyrocks

Share this post


Link to post
Share on other sites



ok so apparently i just had it in the wrong kindof statement.  it seems a 2d array doesn't like to be messed with it a while statement or a do until statement.  after searching this is what i came up with that works.  i have other errors now but at least im past this one hurdle.

$x = 1
$w = 0
Dim $array[30]
dim $array1[30][30]
$max = UBound($ch)
while $x <> $max - 1
$array = StringSplit($ch[$x],"")            ;this just splits the inputed choices into a 2d array of letters

$row = 0
for $s = 1 to UBound($array) -1
$array1[$row][$s] = $array[$s]                 
Next
$w = $w + 1
$x = $x + 1


WEnd

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can.  You just need to make sure the dim's are well checked, prior to adding in the data...In this example, I check bounds, and redim as required:

#include <Array.au3>
Local $aStrings[6]=["a","bc","def","ghij","klmno","p"]
Local $aStringsSplit[UBound($aStrings)][1]

For $i = 0 To UBound($aStringsSplit)-1
    $aTemp = StringSplit($aStrings[$i],"",2)
    If UBound($aTemp)>UBound($aStringsSplit,2) Then ReDim $aStringsSplit[UBound($aStringsSplit)][UBound($aTemp)]
    For $j = 0 To UBound($aTemp)-1
        $aStringsSplit[$i][$j] = $aTemp[$j]
    Next
Next
_ArrayDisplay($aStringsSplit)

Output:

[0]|a||||
[1]|b|c|||
[2]|d|e|f||
[3]|g|h|i|j|
[4]|k|l|m|n|o
[5]|p||||

Without knowing what's in your specific array of strings, this example is the best I can do for you.
 

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Well ty. I did get it to work. Part of my problem was the original list of strings wasn't being passes to the function. But I fixed that as well

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