Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > AutoIt
You last visited: Today at 14:24

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Wert vor ein Array setzen

Discussion on Wert vor ein Array setzen within the AutoIt forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Dec 2015
Posts: 5
Received Thanks: 0
Red face Wert vor ein Array setzen

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
ValleEpvp is offline  
Reply


Similar Threads Similar Threads
c++ array
04/24/2015 - C/C++ - 10 Replies
char titles = { {"Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text"}, {"Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text"}, {"Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text", "Text"}, }; 1>.\InstanceBaseEffect.cpp(683) : error C2440: 'initializing' : cannot convert from 'const...
Array
09/20/2014 - Web Development - 8 Replies
ProtocolNode Object ( => message => Array ( => [email protected] => 1421333354-1233 => 0 => text => 1413364225 => Peter Pan ) => Array ( => ProtocolNode Object ( => body => Array ( ) => => Testlauf ) ) => ) Jemand eine Idee wie an die Array-Werte komme als Beispiel z.B an die Nachricht "Testlauf" oder den Namen "Peter Pan"?
in Beast Spawnpunkt Setzen und Monster Setzen
09/15/2013 - Flyff Private Server - 1 Replies
Hay leute ich wollte mal fragen wie man Spawnpunkte und Monster Spawns setzt in Beast



All times are GMT +2. The time now is 14:24.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.