- Offizieller Beitrag
für ey-jo86:
C
; arrayfunktionen einbinden
; #include <Array.au3>
#include <File.au3>
; Array anlegen für die Datei
Dim $file[1]
; Datei einlesen
$res = _FileReadToArray("C:\test.txt", $file)
_ArrayDisplay($file, "Eingelesene Datei")
; Datei von hinten durchgehen
For $i = $file[0] To 1 Step - 1
; Wenn der suchtext enthalten ist, dann aktuelle Zeile aus dem Array löschen
If StringInStr($file[$i], "suchtext") <> 0 Then _ArrayDelete($file, $i)
Next
; Array zur Kontrolle anzeigen
_ArrayDisplay($file, "Ergebnis")
; Daten aus Array wieder in Datei schreiben
$res = _FileWriteFromArray("C:\test2.txt", $file, 1)
MsgBox(0, "FileWrite-error", $res)
;===============================================================================
;
; Function Name: _ArrayDisplay()
; Description: Displays a 1-dimensional array in a message box.
; Author(s): Brian Keene <brian_keene at yahoo dot com>
;
;===============================================================================
Func _ArrayDisplay(Const ByRef $avArray, $sTitle)
Local $iCounter = 0, $sMsg = ""
If (Not IsArray($avArray)) Then
SetError(1)
Return 0
EndIf
For $iCounter = 0 To UBound($avArray) - 1
$sMsg = $sMsg & "[" & $iCounter & "] = " & StringStripCR($avArray[$iCounter]) & @CR
Next
MsgBox(4096, $sTitle, $sMsg)
SetError(0)
Return 1
EndFunc ;==>_ArrayDisplay
;===============================================================================
;
; Function Name: _ArrayDelete()
; Description: Deletes the specified element from the given array, returning
; the adjusted array.
; Author(s) Cephas <cephas at clergy dot net>
; Modifications Array is passed via Byref - Jos van der zande
;===============================================================================
Func _ArrayDelete(ByRef $avArray, $iElement)
Local $iCntr = 0, $iUpper = 0
If (Not IsArray($avArray)) Then
SetError(1)
Return ""
EndIf
; We have to define this here so that we're sure that $avArray is an array
; before we get it's size.
$iUpper = UBound($avArray) ; Size of original array
; If the array is only 1 element in size then we can't delete the 1 element.
If $iUpper = 1 Then
SetError(2)
Return ""
EndIf
Local $avNewArray[$iUpper - 1]
If $iElement < 0 Then
$iElement = 0
EndIf
If $iElement > ($iUpper - 1) Then
$iElement = ($iUpper - 1)
EndIf
If $iElement > 0 Then
For $iCntr = 0 To $iElement - 1
$avNewArray[$iCntr] = $avArray[$iCntr]
Next
EndIf
If $iElement < ($iUpper - 1) Then
For $iCntr = ($iElement + 1) To ($iUpper - 1)
$avNewArray[$iCntr - 1] = $avArray[$iCntr]
Next
EndIf
$avArray = $avNewArray
SetError(0)
Return 1
EndFunc ;==>_ArrayDelete
Exit
Alles anzeigen
peethebee