I was trying to use BinaryReader.PeekChar to "peek" the next byte, that works
fine unless the byte value's above 127 .... is there anything I can do abouit
it?
thnx,
mikolas 19 7152
Don't you have PeekByte? PeekChar will read a unicode char, this can be
more than 1 byte.
Kind regards
Alexander
"Mikolas" <Mi*****@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com... I was trying to use BinaryReader.PeekChar to "peek" the next byte, that works fine unless the byte value's above 127 .... is there anything I can do abouit it?
thnx, mikolas
Hi Mikolas,
The default constructor for BinaryReader is set to use UTF8 encoding which
will be ascii for the first 127 byte characters but will mean unicode for
characters above 127 (ie reading two bytes etc).
Use the encoding used in the text. This will create a reader with the
default windows page on your machine.
BinaryReader br = new BinaryReader(stream, Encoding.Default);
--
Happy Coding!
Morten Wennevik [C# MVP]
"Morten Wennevik" wrote: Hi Mikolas,
The default constructor for BinaryReader is set to use UTF8 encoding which will be ascii for the first 127 byte characters but will mean unicode for characters above 127 (ie reading two bytes etc).
Use the encoding used in the text. This will create a reader with the default windows page on your machine. BinaryReader br = new BinaryReader(stream, Encoding.Default);
I admit I don't know much about all those different encodings, but .Default
sounds a bit dangerous since I'm writing code that should be running on
different devices. So should I use UnicodeEncoding and then mask the desired
byte?
thanks,
mikolas
-- Happy Coding! Morten Wennevik [C# MVP]
On Mon, 6 Dec 2004 04:59:04 -0800, Mikolas
<Mi*****@discussions.microsoft.com> wrote:
"Morten Wennevik" wrote:
Hi Mikolas,
The default constructor for BinaryReader is set to use UTF8 encoding which will be ascii for the first 127 byte characters but will mean unicode for characters above 127 (ie reading two bytes etc).
Use the encoding used in the text. This will create a reader with the default windows page on your machine. BinaryReader br = new BinaryReader(stream, Encoding.Default);
I admit I don't know much about all those different encodings, but .Default sounds a bit dangerous since I'm writing code that should be running on different devices. So should I use UnicodeEncoding and then mask the desired byte?
thanks, mikolas
-- Happy Coding! Morten Wennevik [C# MVP]
Hard to say. If the text could be in different encodings you would
probably benefit from using Unicode or UTF8. If you only need the
standard default extended English ascii you could get that specific
encoding with
Encoding e = Encoding.GetEncoding("Windows-1252");
Encoding e = Encoding.GetEncoding("ISO-8859-1");
I believe the code table are the same for these two code pages. There is
also "US ASCII" listed under western code pages.
You can read more about Unicode and UTF8 on this page http://www.pobox.com/~skeet/csharp/unicode.html
--
Happy Coding!
Morten Wennevik [C# MVP]
Morten Wennevik <Mo************@hotmail.com> wrote: Hard to say. If the text could be in different encodings you would probably benefit from using Unicode or UTF8. If you only need the standard default extended English ascii you could get that specific encoding with Encoding e = Encoding.GetEncoding("Windows-1252"); Encoding e = Encoding.GetEncoding("ISO-8859-1"); I believe the code table are the same for these two code pages.
No they're not - they differ between 128 and 140.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
On Tue, 7 Dec 2004 11:25:45 -0000, Jon Skeet [C# MVP] <sk***@pobox.com>
wrote: Morten Wennevik <Mo************@hotmail.com> wrote: Hard to say. If the text could be in different encodings you would probably benefit from using Unicode or UTF8. If you only need the standard default extended English ascii you could get that specific encoding with Encoding e = Encoding.GetEncoding("Windows-1252"); Encoding e = Encoding.GetEncoding("ISO-8859-1"); I believe the code table are the same for these two code pages.
No they're not - they differ between 128 and 140.
I see. Which is considered the standard western codepage? Or is the
standard something that differs between europe and usa?
--
Happy Coding!
Morten Wennevik [C# MVP]
Morten Wennevik <Mo************@hotmail.com> wrote: No they're not - they differ between 128 and 140.
I see. Which is considered the standard western codepage? Or is the standard something that differs between europe and usa?
Encoding.Default is Windows 1252, I believe.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
On Tue, 7 Dec 2004 13:25:45 -0000, Jon Skeet [C# MVP] <sk***@pobox.com>
wrote: Morten Wennevik <Mo************@hotmail.com> wrote: > No they're not - they differ between 128 and 140.
I see. Which is considered the standard western codepage? Or is the standard something that differs between europe and usa?
Encoding.Default is Windows 1252, I believe.
Well, on this system, Norwegian Windows 98, Encoding.Default is
iso-8859-1. I believe Encoding.Default varies with whatever codepage the
OS uses.
--
Happy Coding!
Morten Wennevik [C# MVP]
Morten Wennevik <Mo************@hotmail.com> wrote: On Tue, 7 Dec 2004 13:25:45 -0000, Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
Morten Wennevik <Mo************@hotmail.com> wrote: > No they're not - they differ between 128 and 140.
I see. Which is considered the standard western codepage? Or is the standard something that differs between europe and usa? Encoding.Default is Windows 1252, I believe.
Well, on this system, Norwegian Windows 98, Encoding.Default is iso-8859-1.
Interesting. I thought 1252 was the default throughout Western
Europe... Which property did you use to display iso-8859-1 though? The
BodyName property for 1252 returns iso-8859-1, but the others return
Windows-1252.
I believe Encoding.Default varies with whatever codepage the OS uses.
It certainly does.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
On Tue, 7 Dec 2004 15:17:49 -0000, Jon Skeet [C# MVP] <sk***@pobox.com>
wrote: Morten Wennevik <Mo************@hotmail.com> wrote: On Tue, 7 Dec 2004 13:25:45 -0000, Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
> Morten Wennevik <Mo************@hotmail.com> wrote: >> > No they're not - they differ between 128 and 140. >> >> I see. Which is considered the standard western codepage? Or is the >> standard something that differs between europe and usa? > > Encoding.Default is Windows 1252, I believe. >
Well, on this system, Norwegian Windows 98, Encoding.Default is iso-8859-1.
Interesting. I thought 1252 was the default throughout Western Europe... Which property did you use to display iso-8859-1 though? The BodyName property for 1252 returns iso-8859-1, but the others return Windows-1252.
I believe Encoding.Default varies with whatever codepage the OS uses.
It certainly does.
Interesting, I only checked the BodyName and indeed the other values are
1252/windows 1252, but if BodyName reports the codename for mail agents
one would think the two are identical. Odd.
--
Happy Coding!
Morten Wennevik [C# MVP]
Well, this is is strange. Obviously the encoding thing's pretty complex so do
I really have to deal with all this? All I want is to peek one byte ahead ...
I remember like 10 years ago when I started learning programming things like
that were possible(even here in th Czech rep.) - what is it that happened in
the meantime?
Many Thanks,
mikolas
"Morten Wennevik" wrote: On Tue, 7 Dec 2004 15:17:49 -0000, Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
Morten Wennevik <Mo************@hotmail.com> wrote: On Tue, 7 Dec 2004 13:25:45 -0000, Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
> Morten Wennevik <Mo************@hotmail.com> wrote: >> > No they're not - they differ between 128 and 140. >> >> I see. Which is considered the standard western codepage? Or is the >> standard something that differs between europe and usa? > > Encoding.Default is Windows 1252, I believe. >
Well, on this system, Norwegian Windows 98, Encoding.Default is iso-8859-1.
Interesting. I thought 1252 was the default throughout Western Europe... Which property did you use to display iso-8859-1 though? The BodyName property for 1252 returns iso-8859-1, but the others return Windows-1252.
I believe Encoding.Default varies with whatever codepage the OS uses.
It certainly does.
Interesting, I only checked the BodyName and indeed the other values are 1252/windows 1252, but if BodyName reports the codename for mail agents one would think the two are identical. Odd.
-- Happy Coding! Morten Wennevik [C# MVP]
"Alexander Muylaert" wrote: Don't you have PeekByte?
this would certainly be great and I wouldn't have to spend 1hour debugging
but I haven't seen it anywhere...
mikolas
On Wed, 8 Dec 2004 04:31:01 -0800, Mikolas
<Mi*****@discussions.microsoft.com> wrote: Well, this is is strange. Obviously the encoding thing's pretty complex so do I really have to deal with all this? All I want is to peek one byte ahead ... I remember like 10 years ago when I started learning programming things like that were possible(even here in th Czech rep.) - what is it that happened in the meantime?
Many Thanks, mikolas
Well, if you aren't going to read the bytes as characters just use the
overloaded
constructor for the BinaryReader.
new BinaryReader(stream, Encoding.Default);
This should force a character to be considered 8 bits in size so PeekChar
should return a single byte.
--
Happy Coding!
Morten Wennevik [C# MVP]
"Morten Wennevik" wrote: On Wed, 8 Dec 2004 04:31:01 -0800, Mikolas <Mi*****@discussions.microsoft.com> wrote:
Well, this is is strange. Obviously the encoding thing's pretty complex so do I really have to deal with all this? All I want is to peek one byte ahead ... I remember like 10 years ago when I started learning programming things like that were possible(even here in th Czech rep.) - what is it that happened in the meantime?
Many Thanks, mikolas
Well, if you aren't going to read the bytes as characters just use the overloaded constructor for the BinaryReader.
new BinaryReader(stream, Encoding.Default);
This should force a character to be considered 8 bits in size so PeekChar should return a single byte.
I'm sorry but I still don't get it. How do you know that? My SW should also
be running on WinCE and as far as I know there's only unicode.
This is just so weird - why there's PeekChar and not PeekByte, one would
expect to use binary reader for binary reading....
thanks,
mikolas
Mikolas <Mi*****@discussions.microsoft.com> wrote: This should force a character to be considered 8 bits in size so PeekChar should return a single byte.
I'm sorry but I still don't get it. How do you know that? My SW should also be running on WinCE and as far as I know there's only unicode. This is just so weird - why there's PeekChar and not PeekByte, one would expect to use binary reader for binary reading....
I know, it's very strange that there isn't a PeekByte :(
Rather than trust to Encoding.Default, you could use Encoding.ASCII or
Encoding.GetEncoding(28591), the latter of which is ISO-8859-1.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Mikolas,
Hm, I mistakingly though Encoding.Default always would use an 8-bit
encoding, but a simple test proved me wrong. I would use
Encoding.GetEncoding("ISO-8859-1") or any of the encodings you know are
8-bit. You should not however use Encoding.ASCII as that is only 7-bit
and will truncate any values above 127.
--
Happy Coding!
Morten Wennevik [C# MVP]
Morten Wennevik <Mo************@hotmail.com> wrote: Hm, I mistakingly though Encoding.Default always would use an 8-bit encoding, but a simple test proved me wrong. I would use Encoding.GetEncoding("ISO-8859-1") or any of the encodings you know are 8-bit. You should not however use Encoding.ASCII as that is only 7-bit and will truncate any values above 127.
I don't see why that causes an issue if the encoding is only being used
for PeekChar, to detect the end of the file. If it's *not* only being
used for PeekChar, then the encoding of the actual text in the file is
what should be used, whether that's ASCII, ISO-8859-1 or whatever.
Detecting the end of the file might then become significantly more
difficult if the desired encoding is multi-byte.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
On Fri, 10 Dec 2004 13:13:10 -0000, Jon Skeet [C# MVP] <sk***@pobox.com>
wrote: Morten Wennevik <Mo************@hotmail.com> wrote: Hm, I mistakingly though Encoding.Default always would use an 8-bit encoding, but a simple test proved me wrong. I would use Encoding.GetEncoding("ISO-8859-1") or any of the encodings you know are 8-bit. You should not however use Encoding.ASCII as that is only 7-bit and will truncate any values above 127.
I don't see why that causes an issue if the encoding is only being used for PeekChar, to detect the end of the file. If it's *not* only being used for PeekChar, then the encoding of the actual text in the file is what should be used, whether that's ASCII, ISO-8859-1 or whatever. Detecting the end of the file might then become significantly more difficult if the desired encoding is multi-byte.
Well, the original message didn't say anything about only reading the end
of file, nor using it for reading text. PeekChar with Encoding.ASCII will
read 7 bits so a byte value of say 130 would be returned as 63, ie not
what you would want.
--
Happy Coding!
Morten Wennevik [C# MVP]
Morten Wennevik <Mo************@hotmail.com> wrote: Well, the original message didn't say anything about only reading the end of file, nor using it for reading text. PeekChar with Encoding.ASCII will read 7 bits so a byte value of say 130 would be returned as 63, ie not what you would want.
Oops - I was getting confused with a different thread asking why there
isn't a PeekByte method...
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Al Davis |
last post by:
Note: I tried cross-posting this message to several newsgoups,
including comp.lang.perl.misc, c.l.p.moderated,
comp.infosystems.www.authoring.cgi, comp.lang.javascript and
comp.lang.php. Nothing...
|
by: lkrubner |
last post by:
I want to give users the power to edit files from an easy interface, so
I create a form and a PHP script called "fileUpdate". It does a
reasonable about of error checking and prints out some...
|
by: thecrow |
last post by:
Alright, what the hell is going on here?
In the following code, I expect the printed result to be:
DEBUG: frank's last name is burns.
Instead, what I get is:
DEBUG: frank's last name is...
|
by: Brandon J. Van Every |
last post by:
What's better about Ruby than Python? I'm sure there's something. What is
it?
This is not a troll. I'm language shopping and I want people's answers. I
don't know beans about Ruby or have...
|
by: Brandon J. Van Every |
last post by:
I'm realizing I didn't frame my question well.
What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump
up in your chair and scream "Wow! Ruby has *that*? That is SO...
|
by: mike420 |
last post by:
I think everyone who used Python will agree that its syntax is
the best thing going for it. It is very readable and easy
for everyone to learn. But, Python does not a have very good
macro...
|
by: Sarah Tanembaum |
last post by:
Beside its an opensource and supported by community, what's the fundamental
differences between PostgreSQL and those high-price commercial database (and
some are bloated such as Oracle) from...
|
by: Tim |
last post by:
Hi,
I'm experiencing some problem with the following code:
st = File.Open(sFilename, FileMode.Open, FileAccess.ReadWrite)
br = New BinaryReader(st)
Do Until br.PeekChar = -1
Dim buffer()...
|
by: Anil Gupte |
last post by:
Here is my code:
Dim fsReadStream As New FileStream(L3FileName, FileMode.Open,
FileAccess.Read)
Dim brReader As New BinaryReader(fsReadStream)
Dim ByteArray() As Byte
While brReader.PeekChar()...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |