|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Text Files, Encoding and NewLine characterI'm creating a component to read text files. I'm using TextReader with Encoding Text component, because there are several different types of text files and the encoding component translates the bytes from this file to the correct characters. To which one of this text file's types almost all the time '\r\n' is the new line character. But sometimes it could not be, that's why I'm using NewLine property to know exactly who the next line characters are in which case. At that point all work's fine with TextWrite, but hell knows why TextReader doesn't have a NewLine property. Is there any way to identify the NewLine character of a determinate Encode system? or just stop using the NewLine and work only with '\r\n'? Another question, TextReader copies all file from the harddisk as soon as it is initiated, or it copies part of the file when I'm using Read();? Thank you, Roby Eisenbraun Martins Roby Eisenbraun Martins
<RobyEisenbraunMart***@discussions.microsoft.com> wrote: > I'm creating a component to read text files. Character encoding is a separate concern from which character or > I'm using TextReader with Encoding Text component, because there are > several different types of text files and the encoding component translates > the bytes from this file to the correct characters. > To which one of this text file's types almost all the time '\r\n' is the > new line character. But sometimes it could not be, that's why I'm using > NewLine property to know exactly who the next line characters are in which > case. > At that point all work's fine with TextWrite, but hell knows why > TextReader doesn't have a NewLine property. > Is there any way to identify the NewLine character of a determinate > Encode system? or just stop using the NewLine and work only with '\r\n'? sequence of characters represents a new line. > Another question, TextReader copies all file from the harddisk as soon It buffers some input, but certainly not all of it. Some of the > as it is initiated, or it copies part of the file when I'm using Read();? StreamReader constructors allow you to specify the size of the buffer. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too Jon Skeet [C# MVP]" wrote:
Show quoteHide quote > Roby Eisenbraun Martins Ok, then why we have the NewLine in the TextWriter? Encoding class does > <RobyEisenbraunMart***@discussions.microsoft.com> wrote: > > I'm creating a component to read text files. > > I'm using TextReader with Encoding Text component, because there are > > several different types of text files and the encoding component translates > > the bytes from this file to the correct characters. > > To which one of this text file's types almost all the time '\r\n' is the > > new line character. But sometimes it could not be, that's why I'm using > > NewLine property to know exactly who the next line characters are in which > > case. > > At that point all work's fine with TextWrite, but hell knows why > > TextReader doesn't have a NewLine property. > > Is there any way to identify the NewLine character of a determinate > > Encode system? or just stop using the NewLine and work only with '\r\n'? > > Character encoding is a separate concern from which character or > sequence of characters represents a new line. not have a NewLine to which case? > Thank you> > Another question, TextReader copies all file from the harddisk as soon > > as it is initiated, or it copies part of the file when I'm using Read();? > > It buffers some input, but certainly not all of it. Some of the > StreamReader constructors allow you to specify the size of the buffer. Show quoteHide quote > > -- > Jon Skeet - <sk***@pobox.com> > http://www.pobox.com/~skeet > If replying to the group, please do not mail me too > Roby Eisenbraun Martins
<RobyEisenbraunMart***@discussions.microsoft.com> wrote: > > Character encoding is a separate concern from which character or Because it makes sense to be writing a file with a particular newline > > sequence of characters represents a new line. > > Ok, then why we have the NewLine in the TextWriter? string/character, whatever the encoding is. > Encoding class does not have a NewLine to which case? Because as I said, they're separate concerns - what you use for a newline is entirely separate from the encoding used to represent characters. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too "Jon Skeet [C# MVP]" wrote: Yes there is a constructor that allow me to inform the buffer size, but > > Another question, TextReader copies all file from the harddisk as soon > > as it is initiated, or it copies part of the file when I'm using Read();? > > It buffers some input, but certainly not all of it. Some of the > StreamReader constructors allow you to specify the size of the buffer. with it I have to inform the ENCODING format from the file that I really don't know, that's why I am using the StreamReader, because It is the only way to identify Encoding text. In this case, how can I set Buffer size, if I don't know the other parameters? Roby Eisenbraun Martins
<RobyEisenbraunMart***@discussions.microsoft.com> wrote: > "Jon Skeet [C# MVP]" wrote: Even if you don't set the other parameters, they have default values > > > Another question, TextReader copies all file from the harddisk as soon > > > as it is initiated, or it copies part of the file when I'm using Read();? > > > > It buffers some input, but certainly not all of it. Some of the > > StreamReader constructors allow you to specify the size of the buffer. > > Yes there is a constructor that allow me to inform the buffer size, but > with it I have to inform the ENCODING format from the file that I really > don't know, that's why I am using the StreamReader, because It is the only > way to identify Encoding text. In this case, how can I set Buffer size, if I > don't know the other parameters? effectively - if you don't set the encoding, UTF-8 is used. In other words, using new StreamReader (stream) is equivalent to new StreamReader (stream, Encoding.UTF8, true, 1024) -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Other interesting topics
A challenge to all MVP's.......GET A J.O.B. for once in your life
Windows service Unable to access mapped drives on XP and 2003 Boxe My application works fine in debug mode but does not work in release mode. Strange Excel importing problem Parameter Methods Performance (val,ref,out) Process.Start("MyComputer"); Checking for implementation of an interface Simple architecture question. Finalize Queue (WinDBG / SOS) Detecting overriding with reflection? |
|||||||||||||||||||||||