Wert vor ein Array setzen

01/18/2016 16:35 ValleEpvp#1
Hallo, ich habe ein kleines Problem mit meinem Script.

Leider gehen mir die Ideen aus, um folgendes umzusetzen:


​Ich habe eine Datei mit Ranges (von-bis).

Ich lese die Datei ein und speichere sie in Arrays, getrennt durch "-".

Nun gebe ich einen von- und einen bis-wert ein. Diese beiden Werte sollen in die eingelesene Datei (bzw. die Arrays übernommen werden.

So sieht die urspruchsdatei aus:

3915547-3915549
3915553-3921459
3921490-3931753
3931764-3976050

und so soll sie dann ausgegeben werden:

3915547-3915549
3915553-3921459
3921490-3921491
3921494-3931753
3931764-3976050

Leider habe ich keine vernünftige Idee, um die Zeilenumbrüche VOR die zweite Array (3931753) zu bekommen.

Hat jemand vielleicht eine Idee parrat ? Bzw. ist dies überhaupt möglich so ohne weiteres Splitten?

Freundliche Grüße

Hier mein KOMPLETTER Code:

Code:
#include "Array.au3"
#include <File.au3>

$fileName = "V:\Software\Tools\TEST_GS_MASKE\Testdatei\GSD.txt"
$fileAsArray = FileReadToArray($fileName)

$lineCnt = UBound($fileAsArray)

_log("Read file '" & $fileName & "' with '" & $lineCnt & "' lines")

$outpout = @DesktopDir &"\Neue_GS_Testdatei.txt"

; parse file into array of format [i][0] = start and [i][1] = end of range
Local $rangeAmount = 0
Dim $tmpArray[$lineCnt][2]
For $i = 0 To $lineCnt - 1
    Local $currentLine = $fileAsArray[$i]
    Dim $split = StringSplit($currentLine, "-")

    If($split[0] <> 2) Then
        _log("Could not split line '" & $currentLine & "' into two numbers.")
        Exit(1)
    EndIf

    Local $start = String($split[1])
    Local $end =   String($split[2])
    _log($start & "-" & $end)
    $tmpArray[$i][0] = $start
    $tmpArray[$i][1] = $end

    $rangeAmount += 1
 Next


; _ArrayDisplay($tmpArray)

; read a new range
$newNrFrom = String(InputBox("test1", "von")) ; parse input as nr
$newNrTo = String(InputBox("test1", "bis"))

_log("Neue Range: '" & $newNrFrom & "-" & $newNrTo & "'.")
If($newNrFrom >= $newNrTo) Then
    _log("Error: VON-Wert muss kleiner als der BIS-Wert sein")
    Exit(2)
EndIf

; (TODO) > Fast fertig ?!
; update ranges
For $i = 0 To $rangeAmount - 1

    If($tmpArray[$i][0] <= $newNrFrom And $tmpArray[$i][1] >= $newNrFrom) Then
        _log($newNrFrom & " is in range of "&$tmpArray[$i][0]&" to "&$tmpArray[$i][1])

;~ msgbox(0,"",$tmpArray[$i][0])
;~ msgbox(0,"",$tmpArray[$i][1])

    $WasIstI = $i
$ReplaceTo = ""
$tmpArray[$i][1] = $ReplaceTo
StringReplace($tmpArray,$tmpArray[$i][1],$newNrFrom-1)


    $array_add_1 = $tmpArray[$i][1] &  @crlf & $ReplaceTo & "-" & $newNrTo+1
	;$array_add_2 = $newNrFrom+1 & "-" & $tmpArray[$i][0] &  @CRLF & $tmpArray[$i][1] & "-" & $newNrTo-1 & @CRLF


;msgbox(0,"",$tmpArray[$i][0] & $tmpArray[$i][1] & $array_add_1)

;~ Dim $tmpArray[$lineCnt][2]

;~     test, ob neuer BIS-Wert kleiner als der alte IST-Wert
	   If($tmpArray[$i][1] >= $newNrTo) Then
       _log($newNrTo & " is in range of "&$tmpArray[$i][0]&" to "&$tmpArray[$i][1])
	   Msgbox(0,"","is smaller than old")
	   log($tmpArray[$i][0]&"-"&$tmpArray[$i][1])
	   EndIf

;~ $del1 = _ArrayDelete($tmpArray[$i][0], $WasIstI)
;~ MsgBox(0,"",$del1)
;~ $del2 = _ArrayDelete($tmpArray[$i][1], $WasIstI)
;~ MsgBox(0,"",$del2)
;~ MsgBox(0,"",$WasIstI)


    EndIf

Next

; TODO Save in file

_ArrayDisplay($tmpArray)

;Stringreplace($tmpArray,$tmpArray[$i][1],$tmpArray[$i][1]+1)

Stringreplace($tmpArray,"|","-")
_ArrayInsert($tmpArray,$WasIstI,$array_add_1)
;_ArrayInsert($tmpArray,$WasIstI+1,$array_add_2)
_FileWriteFromArray($outpout, $tmpArray)

Stringreplace($outpout,"|","-")
;Dim $split = StringSplit($outpout, "-")
_ArrayDisplay($tmpArray)

;MsgBox(0,"",$element_one & " muss verändert werden")
;MsgBox(0,"",$WasIstI)

Func _log($message)
    ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & @TAB & $message & @CRLF)
 EndFunc