Re: convert nulls to spaces in file

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Mythran (kip_potter_at_hotmail.comREMOVETRAIL)
Date: 10/21/04


Date: Thu, 21 Oct 2004 13:22:06 -0700

Hrm, how about read in the file to a string and do a split with the null
char being the delimiter? I haven't tried it and don't know if it will
work...but what the heck, worth a try eh?

Mythran

"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
news:O$T6oD6tEHA.1404@TK2MSFTNGP11.phx.gbl...
> Brian,
> I would simply open it with a System.IO.FileStream, read a buffer full of
> bytes, change the null bytes to AscW(" "c) then write the buffer to a
> second FileStream.
>
> Something like:
>
> Imports System.IO
>
> Dim input As New FileStream("input.txt", FileMode.Open)
> Dim output As New FileStream("output.txt", FileMode.Create)
>
> Dim buffer(1023) As Byte
> Dim length As Integer
> Do
> length = input.Read(buffer, 0, buffer.Length)
> For index As Integer = 0 To length - 1
> If buffer(index) = 0 Then
> buffer(index) = AscW(" "c)
> End If
> Next
> output.Write(buffer, 0, length)
> Loop Until length < buffer.Length
> input.Close()
> output.Close()
>
> Note the above may not work correctly for non Ansi 8-bit encodings,
> however it should be easy enough to adapt.
>
> Hope this helps
> Jay
>
>
> "Brian Henry" <brianiupmsdn@newsgroups.nospam> wrote in message
> news:eDD1F05tEHA.220@TK2MSFTNGP15.phx.gbl...
>> first question... I have a flat file which unfortinuatly has columns
>> seperated by nulls instead of spaces (a higher up company created it this
>> way for us) is there anyway to do a readline with this and not have it
>> affected by the null? because it is right now causes truncated data at
>> wierd places... but as soon as i manually with a hex editor change
>> char(00) to char(20) in the files it reads prerfectly... which leads me
>> to my 2nd question... if you cant do what i said in the 1st question, is
>> there a way to go through the file, convert the nulls to spaces and save
>> it back then open it as a stream reader to read it line by line? the
>> lines are delimited by CR+LF's thanks!
>>
>
>



Relevant Pages