Sign in to follow this  
Followers 0
Dino

Array help for Newbie

5 posts in this topic

Hello everybody.

This is the content of array.

bla,bla,bla
I will,"do my best","in order to understand","arrays"
bla,bla,bla
I will,"do my best","in order to understand","GUI Concepts"
bla,bla,bla
bla,bla,bla
I will,"do my best","in order to understand","String Managements"
I will,"do my best","in order to understand","Tray Functions"

I want rewrite the array in this manner:

bla,bla,bla
I will,"do my best","in order to understand","arrays","GUI Concepts","String Managements","Tray Functions"

And this is the code

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

Dim $aRecords, $NewArr[1], $IsFound=0, $NewArrCnt=0, $Extended=0


_FileReadToArray('Test.txt',$aRecords)

  For $i = 1 To UBound($aRecords) - 1
   $StringSplit = StringSplit(StringStripWS($aRecords[$i], 8), ',')
    $IsFound = 0
      For $j = 1 To UBound($NewArr)-1
       $NewStringSplit = StringSplit(StringStripWS($NewArr[$j], 8), ',')
        If $StringSplit[3] == $NewStringSplit[3] Then
           $NewArr[$j] = $aRecords[$i] & ',' & $NewStringSplit[4]
                         $IsFound = 1
                $Extended += 1
                ExitLoop
            EndIf
        Next
        If Not $IsFound Then
            $NewArrCnt += 1
            ReDim $NewArr[$NewArrCnt+1]
            $NewArr[$NewArrCnt] =$aRecords[$i]
        EndIf
    Next
    $NewArr[0] = UBound($NewArr) - 1


 _ArrayDisplay($NewArr, "test")

But the result is only:

I will,"do my best","in order to understand","Tray Functions","String Managements"

Can someone help me to fix my problem

Thanks by advance.

Share this post


Link to post
Share on other sites



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

Dim $aRecords, $NewArr[1], $IsFound=0, $NewArrCnt=0, $Extended=0
_FileReadToArray('Test.txt',$aRecords)
oÝ÷ Ûú®¢×*Ê2¢êÞiÛayø¥z)í¢Ø^jºÚËMúi¢·lªê-y«­¢+ؽÈÀÌØí¤ôÄQ¼U   ½Õ¹ ÀÌØíI½É̤´Ä(ÀÌØíMÑÉ¥¹MÁ±¥ÐôMÑÉ¥¹MÁ±¥Ð¡MÑÉ¥¹MÑÉ¥Á]L ÀÌØíI½ÉÍlÀÌØí¥t°à¤°Ìäì°Ìäì¤(oÝ÷ Ûú®¢×¢·rbê¶W¢Múi¢·lʬ¦X­¶¬¶¸§¼¢i²)í¡©ÝjºÚÉÆ¥çtߤ­®)àJb¶«¨µæ®¶­sbb33c´4f÷VæBÒ¢f÷"b33c¶¢ÒFòT&÷VæBb33c´æWt'"Ó
Now you are referencing an array that has no data in it called $NewArr...??? Where did that come from? I see that you Dim'ed the array at the top, but there is nothing in it. And after this point you are splitting stings on commas again, which has already been done. Why splitting again?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Now you are referencing an array that has no data in it called $NewArr...??? Where did that come from? I see that you Dim'ed the array at the top, but there is nothing in it. And after this point you are splitting stings on commas again, which has already been done. Why splitting again?

My intention was to recreate a new array that contain both 'untouched' and merged value like this

bla,bla,bla
I will,"do my best","in order to understand","arrays","GUI Concepts","String Managements","Tray Functions"
bla,bla,bla
bla,bla,bla
bla,bla,bla
..............

Share this post


Link to post
Share on other sites

$sText = 'bla,bla,bla' & @CRLF & _
                'I will,"do my best","in order to understand","arrays"' & @CRLF & _
                'bla,bla,bla' & @CRLF & _
                'I will,"do my best","in order to understand","GUI Concepts"' & @CRLF & _
                'bla,bla,bla' & @CRLF & _
                'bla,bla,bla' & @CRLF & _
                'I will,"do my best","in order to understand","String Managements"' & @CRLF & _
                'I will,"do my best","in order to understand","Tray Functions"'
$sOutput = _StrReturnPatternArray($sText, 'I will,"do my best","in order to understand"')
MsgBox(0,0, $sOutput)

Func _StrReturnPatternArray($sString, $sPattern, $vDelimit = ',', $sStart = '"', $sEnd = '"')
    Local $sHold = $sPattern, $iCC, $xCC
    Local $aArray = StringRegExp($sString, '(?s)(?i)' & $sPattern & $vDelimit & '(' & $sStart & '.*?' & $sEnd & ')', 3)
    If IsArray($aArray) = 0 Then Return SetError(1, 0, '')
    ;Merge $sPattern with found array
    For $iCC = 0 To UBound($aArray) - 1
        If $aArray[$iCC] <> '' Then $sHold &= $vDelimit & $aArray[$iCC]
    Next
    ;Replace 1st instance of pattern with new pattern delete all other patterns
    Local $aSplit = StringSplit(StringStripCR($sString), @LF), $nFound = 0, $sReturn
    For $xCC = 1 To UBound($aSplit) - 1
        If $nFound = 0 And StringInStr($aSplit[$xCC], $sPattern) Then
            $sReturn &= $sHold & @CRLF
            $nFound = 1
        ElseIf StringInStr($aSplit[$xCC], $sPattern) = 0 Then
            $sReturn &= $aSplit[$xCC] & @CRLF
        EndIf
    Next
    Return StringTrimRight($sReturn, 2)
EndFunc


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

$sText = 'bla,bla,bla' & @CRLF & _
                'I will,"do my best","in order to understand","arrays"' & @CRLF & _
                'bla,bla,bla' & @CRLF & _
                'I will,"do my best","in order to understand","GUI Concepts"' & @CRLF & _
                'bla,bla,bla' & @CRLF & _
                'bla,bla,bla' & @CRLF & _
                'I will,"do my best","in order to understand","String Managements"' & @CRLF & _
                'I will,"do my best","in order to understand","Tray Functions"'
$sOutput = _StrReturnPatternArray($sText, 'I will,"do my best","in order to understand"')
MsgBox(0,0, $sOutput)

Func _StrReturnPatternArray($sString, $sPattern, $vDelimit = ',', $sStart = '"', $sEnd = '"')
    Local $sHold = $sPattern, $iCC, $xCC
    Local $aArray = StringRegExp($sString, '(?s)(?i)' & $sPattern & $vDelimit & '(' & $sStart & '.*?' & $sEnd & ')', 3)
    If IsArray($aArray) = 0 Then Return SetError(1, 0, '')
    ;Merge $sPattern with found array
    For $iCC = 0 To UBound($aArray) - 1
        If $aArray[$iCC] <> '' Then $sHold &= $vDelimit & $aArray[$iCC]
    Next
    ;Replace 1st instance of pattern with new pattern delete all other patterns
    Local $aSplit = StringSplit(StringStripCR($sString), @LF), $nFound = 0, $sReturn
    For $xCC = 1 To UBound($aSplit) - 1
        If $nFound = 0 And StringInStr($aSplit[$xCC], $sPattern) Then
            $sReturn &= $sHold & @CRLF
            $nFound = 1
        ElseIf StringInStr($aSplit[$xCC], $sPattern) = 0 Then
            $sReturn &= $aSplit[$xCC] & @CRLF
        EndIf
    Next
    Return StringTrimRight($sReturn, 2)
EndFunc

Thanks SmOke_N :)

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