Sign in to follow this  
Followers 0
joeloyzaga

create a 2 dimensional array from text

3 posts in this topic

#1 ·  Posted (edited)

the text is comma delimited and is in 16 lines so the array would be $aArray[16][30] and each text value needs quotes(") around them. Blank array values are to be skipped....

so the one dimensional manual way would be...

$aTestcaseArray0 = StringSplit("Result,Test To Be Run Y/N,ID,Test Identifier,Overall Expected Result,Action,Amount,Actual Amount Found,Cashout,Actual Cashout Found,Text to find 1,Text to find 2,Text to find 3,Text to find 4,Text to find 5,Text to find 6,Text to find 7,Text to find 8,Text to find 9,Text to find 12,Text to find 13,Text to find 14,",",")

$aTestcaseArray1 = StringSplit(",,TRANSACTION02,Purchase transaction with DECLINED result,POS does not approve the sale (declined),Do a purchase for $100.01,10001,,,,Merchant,Address line 1,Address line 2,Tyro EFTPOS,Card: ,EFTPOS,Purchase AUD $100.01,Total AUD $100.01,DECLINED 01,Terminal ID: ,Transaction Ref: ,Authorisation No: ,|TODAY|",",")

$aTestcaseArray2 = StringSplit(",,TRANSACTION01,Purchase transaction with APPROVED result,POS approves the sale,Do a purchase for $100.00,10000,,,,Merchant,Address line 1,Address line 2,Tyro EFTPOS,Card: ,EFTPOS,Purchase AUD $100.00,Total AUD $100.00,APPROVED 00,Terminal ID: ,Transaction Ref: ,Authorisation No: ,|TODAY|",",")

$aTestcaseArray3 = StringSplit(",,TRANSACTION03,Purchase transaction with CANCELLED result,POS does not approve the sale (cancelled),Do a purchase for $600.00,60000,,,,Merchant,Address line 1,Address line 2,TRANSACTION CANCELLED,Tyro EFTPOS,|TODAY|,,,,,,,",",")

$aTestcaseArray4 = StringSplit(",,TRANSACTION04,Purchase transaction with REVERSED result,POS does not approve the sale (reversed),Do a purchase for $6.60,660,,,,Merchant,Address line 1,Address line 2,TRANSACTION CANCELLED,Tyro EFTPOS,Card: ,EFTPOS,Reversal AUD $6.60, Total AUD $6.60,CANCELLED 00,|TODAY|,,",",")

$aTestcaseArray5 = StringSplit(",,TRANSACTION05,Purchase transaction with SYSTEM ERROR result,POS does not approve the sale (system error),Do a purchase for $8.80,880,,,,Merchant,Address line 1,Address line 2,Tyro EFTPOS,Card: ,EFTPOS,Purchase AUD $8.80,Total AUD $8.80,DECLINED 01,Terminal ID: ,Transaction Ref: ,Authorisation No: ,|TODAY|",",")

$aTestcaseArray6 = StringSplit(",,TRANSACTION06,Purchase with cashout transaction with APPROVED result,POS approves the sale and prompts the user to offer the cash to the user,Do a purchase for $100.00 with cashout of any amount,10000,,1000,,Merchant,Address line 1,Address line 2,Tyro EFTPOS,Card: ,EFTPOS,Purchase AUD $100.00,Total AUD $100.00,DECLINED 01,Terminal ID: ,Transaction Ref: ,Authorisation No: ,|TODAY|",",")

$aTestcaseArray7 = StringSplit(",,TRANSACTION07,Purchase with cashout transaction with DECLINED result,POS does not approve the sale,Do a purchase for $100.01 with cashout of any amount,10001,,1000,,Merchant,Address line 1,Address line 2,Tyro EFTPOS,Card: ,EFTPOS,Purchase AUD $100.00,Total AUD $100.00,APPROVED 00,Terminal ID: ,Transaction Ref: ,Authorisation No: ,|TODAY|","'")

$aTestcaseArray8 = StringSplit(",,TRANSACTION08,Purchase with cashout transaction with CANCELLED result,POS does not approve the sale,Do a purchase for $600.00 with cashout of any amount,60000,,1000,,Merchant,Address line 1,Address line 2,Tyro EFTPOS,Card: ,EFTPOS,Purchase AUD $100.00,Total AUD $100.00,APPROVED 00,Terminal ID: ,Transaction Ref: ,Authorisation No: ,|TODAY|",",")

$aTestcaseArray9 = StringSplit(",,TRANSACTION09,Purchase with cashout transaction with REVERSED result,POS does not approve the sale,Do a purchase for $6.60 with cashout of any amount,660,,1000,,Merchant,Address line 1,Address line 2,Tyro EFTPOS,Card: ,EFTPOS,Purchase AUD $100.00,Total AUD $100.00,APPROVED 00,Terminal ID: ,Transaction Ref: ,Authorisation No: ,|TODAY|",",")

$aTestcaseArray10 = StringSplit(",,TRANSACTION10,Purchase with cashout transaction with SYSTEM ERROR result,POS does not approve the sale,Do a purchase for $8.80 with cashout of any amount,880,,1000,,Merchant,Address line 1,Address line 2,Tyro EFTPOS,Card: ,EFTPOS,Purchase AUD $100.00,Total AUD $100.00,APPROVED 00,Terminal ID: ,Transaction Ref: ,Authorisation No: ,|TODAY|",",")

$aTestcaseArray11 = StringSplit(",,TRANSACTION11,Refund transaction with APPROVED result,POS refunds the sale,Do a refund for $100.00,10000,,,,Merchant,Address line 1,Address line 2,Tyro EFTPOS,Card: ,EFTPOS,Purchase AUD $100.00,Total AUD $100.00,APPROVED 00,Terminal ID: ,Transaction Ref: ,Authorisation No: ,|TODAY|",",")

$aTestcaseArray12 = StringSplit(",,TRANSACTION12,Refund transaction with DECLINED result,POS does not refund the sale,Do a refund for $100.01,10001,,,,Merchant,Address line 1,Address line 2,Tyro EFTPOS,Card: ,EFTPOS,Purchase AUD $100.00,Total AUD $100.00,APPROVED 00,Terminal ID: ,Transaction Ref: ,Authorisation No: ,|TODAY|",",")

$aTestcaseArray13 = StringSplit(",,TRANSACTION13,Refund transaction with CANCELLED result,POS does not refund the sale,Do a refund for $600.00,60000,,,,Merchant,Address line 1,Address line 2,Tyro EFTPOS,Card: ,EFTPOS,Purchase AUD $100.00,Total AUD $100.00,APPROVED 00,Terminal ID: ,Transaction Ref: ,Authorisation No: ,|TODAY|",",")

$aTestcaseArray14 = StringSplit(",,TRANSACTION14,Refund transaction with REVERSED result,POS does not refund the sale,Do a refund for $6.60,660,,,,Merchant,Address line 1,Address line 2,Tyro EFTPOS,Card: ,EFTPOS,Purchase AUD $100.00,Total AUD $100.00,APPROVED 00,Terminal ID: ,Transaction Ref: ,Authorisation No: ,|TODAY|",",")

$aTestcaseArray15 = StringSplit(",,TRANSACTION15,Refund transaction with SYSTEM ERROR result,POS does not refund the sale,Do a refund for $8.80,880,,,,Merchant,Address line 1,Address line 2,Tyro EFTPOS,Card: ,EFTPOS,Purchase AUD $100.00,Total AUD $100.00,APPROVED 00,Terminal ID: ,Transaction Ref: ,Authorisation No: ,|TODAY|",",")

$aTestcaseArray16 = StringSplit(",,TRANSACTION16,Refund with cashout,POS does not allow cashout to be entered for a refund,Try to do a refund with cashout,60000,,1000,,Merchant,Address line 1,Address line 2,Tyro EFTPOS,Card: ,EFTPOS,Purchase AUD $100.00,Total AUD $100.00,APPROVED 00,Terminal ID: ,Transaction Ref: ,Authorisation No: ,|TODAY|",",")

how to make all 16 arrays into 1 2 dimensional one?

Edited by joeloyzaga

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello joeloyzaga,

You have the general idea, however that is just too much coding for a simple little project. I am assuming that you are reading the text from a file. If this is correct, than this short but sweet example should do exactly what you have asked for.

#include <File.au3>
#include <Array.au3>

Local $sFilePath = ;Add path to the file your reading here
Local $iFileLines = _FileCountLines( $sFilePath )
Local $aMyArray[$iFileLines][30]
Local $aFileText = _FileReadToArray( $sFilePath, $aArray)

For $line = 0 To UBound( $aArray) - 1
    $aLine = StringSplit( $aArray[$line], ",", 2 )
    For $col = 0 To UBound($aline) - 1
        If IsNumber($aline[$col]) Then
            $aMyArray[$line][$col] = $aline[$col]
        Else
            $aMyArray[$line][$col] = '"' & $aline[$col] & '"'
        EndIf
    Next
Next

_ArrayDisplay($aMyArray)

Hope this helps!

Good Luck & Happy Coding!

Realm

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

#include <Array.au3>

Dim $RtArrayC[1][1]
$RtArrayA = StringSplit(FileRead("TextFile.txt"),@LF)
For $i = 1 To $RtArrayA[0]
$RtArrayA[$i] = StringTrimRight($RtArrayA[$i],1) ; Trim @CR
$RtArrayA[$i] = StringTrimLeft($RtArrayA[$i],2) ; Trim ,,
if StringIsSpace($RtArrayA[$i]) Or $RtArrayA[$i] == "" Then ContinueLoop
$RtArrayB = StringSplit($RtArrayA[$i],",")
For $j = 1 To $RtArrayB[0]
if StringIsSpace($RtArrayB[$j]) Or $RtArrayB[$j] == "" Then ContinueLoop
if UBound($RtArrayC,2) < $j Then ReDim $RtArrayC[UBound($RtArrayC)][$j]
$RtArrayC[UBound($RtArrayC) - 1][$j - 1] = '"' & $RtArrayB[$j] & '"'
Next
ReDim $RtArrayC[UBound($RtArrayC) + 1][UBound($RtArrayC,2)]
Next
if UBound($RtArrayC) > 1 Then ReDim $RtArrayC[UBound($RtArrayC) - 1][UBound($RtArrayC,2)]
_ArrayDisplay($RtArrayC,"")

Edited by wolf9228

صرح السماء كان هنا

 

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