Jump to content
Sign in to follow this  
Home Bunny

FileReadLine -- File contains NUL

Recommended Posts

Home Bunny

I'm reading files to convert the content to a SQL database.

The thing i'm having is following:

In my files (opened in SciTe) have sometimes a 'NUL' seperator:

NUL;

(the NUL is visible in white text, black background)

with FileReadLine a empty string is returned, also it isn't posible to copy the 'NUL', gives also a empty string ...

How can i proceed to read these lines?

Share this post


Link to post
Share on other sites
Home Bunny

Found it, the NUL character ==> StringToBinary( $chars ) = 0x00

for the ones that have the same problem:

#include <Array.au3>

Local $avArray[1]
local $Line, $Line2
$i = 0

$file = FileOpen("Mydata.txt",0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop

    If StringToBinary( $chars ) <> 0x00 Then
    
        if $chars <> @LF Then
            $Line2 &= $chars
        Else
            If $Line2 <> "" Then
                _ArrayAdd($avArray, $Line2)
            EndIf
            $Line2 = ""
        EndIf
    EndIf
Wend

FileClose($file)
_ArrayDisplay($avArray, $file)

Regards

Edited by Home Bunny

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.