Modify ↓
Opened 15 years ago
Closed 13 years ago
#1831 closed Bug (Fixed)
_FileCountLines does not handles null characters
| Reported by: | Owned by: | ||
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | 3.3.6.1 | Severity: | None |
| Keywords: | file.au3 _FileCountLines | Cc: |
Description
When using _FileCountLines on a text file containing some NULL (=Chr(0)) the function does not report the whole number of lines.
The function only return the number of lines before the first NULL character.
To avoid this, I propose to include a StrinReplace to delete the NULL characters as below:
Func _FileCountLines($sFilePath) Local $hFile = FileOpen($sFilePath, $FO_READ) If $hFile = -1 Then Return SetError(1, 0, 0) Local $sFileContent = StringStripWS(StringReplace(FileRead($hFile), Chr(0), ""), 2) ;****here is the modified line**** FileClose($hFile) msgbox(0, "", $sFileContent) Local $aTmp If StringInStr($sFileContent, @LF) Then $aTmp = StringSplit(StringStripCR($sFileContent), @LF) ElseIf StringInStr($sFileContent, @CR) Then $aTmp = StringSplit($sFileContent, @CR) Else If StringLen($sFileContent) Then Return 1 Else Return SetError(2, 0, 0) EndIf EndIf Return $aTmp[0] EndFunc
Best regards,
Fabien OBRIER
Attachments (1)
Change History (6)
by , 15 years ago
| Attachment: | testNull.txt added |
|---|
comment:1 by , 15 years ago
Oups! In the script please ignore the line:
msgbox(0, "", $sFileContent)
comment:2 by , 15 years ago
Problem is in the StringStripCR() function. Its clipping strings at the NUL-character. See ticket #1832
comment:3 by , 15 years ago
| Resolution: | → Wont Fix |
|---|---|
| Status: | new → closed |
comment:4 by , 13 years ago
| Resolution: | Wont Fix |
|---|---|
| Status: | closed → reopened |
comment:5 by , 13 years ago
| Resolution: | → Fixed |
|---|---|
| Status: | reopened → closed |
Note:
See TracTickets
for help on using tickets.

sample txt file with NULL on line5