Func _FileReadToArray($sFilePath, ByRef $aArray)
Local $hFile = FileOpen($sFilePath, $FO_READ)
If $hFile = -1 Then Return SetError(1, 0, 0);; unable to open the file
;; Read the file and remove any trailing white spaces
Local $aFile = FileRead($hFile, FileGetSize($sFilePath))
;~ $aFile = StringStripWS($aFile, 2)
; remove last line separator if any at the end of the file
If StringRight($aFile, 1) = @LF Then $aFile = StringTrimRight($aFile, 1)
If StringRight($aFile, 1) = @CR Then $aFile = StringTrimRight($aFile, 1)
FileClose($hFile)
If StringInStr($aFile, @LF) Then
$aArray = StringSplit(StringStripCR($aFile), @LF)
ElseIf StringInStr($aFile, @CR) Then ;; @LF does not exist so split on the @CR
$aArray = StringSplit($aFile, @CR)
Else ;; unable to split the file
If StringLen($aFile) Then
Dim $aArray[2] = [1, $aFile]
Else
Return SetError(2, 0, 0)
EndIf
EndIf
Return 1
EndFunc ;==>_FileReadToArray
用打开的... |