acn_file.au3函数不知道为什么没有修正。
以前收藏的以下两个函数都可以正确返回含有中文的文本文件的行数,有兴趣测试一下。
$line=_FileCountLinesEx('1.txt')
MsgBox(0,0,FileReadLine('1.txt',Random(1,$line,1)))
Func _FileCountLinesEx($sFilePath)
Local $iCountLines = 0
Local $sFRead = FileRead($sFilePath)
If @error = -1 Then Return SetError(1, 0, 0)
If @error <> 0 Then Return SetError(2, 0, 0)
$sFRead = StringReplace($sFRead, @CRLF, "")
$iCountLines += @extended
$sFRead = StringReplace($sFRead, @CR, "")
$iCountLines += @extended
StringReplace($sFRead, @LF, "")
$iCountLines += @extended
Return $iCountLines + 1
EndFunc
Func _FileCountLinesX($sFilePath)
Local $hFile, $sFileContent, $aTmp
$hFile = FileOpen($sFilePath, 0)
If $hFile = -1 Then Return SetError(1, 0, 0)
$sFileContent = FileRead($hFile, FileGetSize($sFilePath))
FileClose($hFile)
If StringInStr($sFileContent, @LF) Then
$aTmp = StringSplit(StringStripCR($sFileContent), @LF)
ElseIf StringInStr($sFileContent, @CR) Then
$aTmp = StringSplit($sFileContent, @CR)
Else
If StringLen($sFileContent) > 0 Then Return 1
Return SetError(2, 0, 0)
EndIf
Return $aTmp[0]
EndFunc ;==>__FileCountLines
|