MemoryStream.WriteByte()

  • Thread starter Thread starter John A Grandy
  • Start date Start date
J

John A Grandy

Dim ms As MemoryStream = New MemoryStream(100)

ms.WriteByte("=")

triggers invalid cast error ...

but

ms.WriteByte(Asc("="c))

does not ...

but isn't Asc() producing a 2-byte representation of a Char
 
Dim ms As MemoryStream = New MemoryStream(100)

ms.WriteByte("=")

triggers invalid cast error ...

but

ms.WriteByte(Asc("="c))

does not ...

but isn't Asc() producing a 2-byte representation of a Char

but the value is less then 256, so can be cast into a byte... This might
complain though with Option Strict On, since it would be a narrowing
conversion (you do have option strict on, right? :)
 
John,
In addition to Tom's comment.

Asc returns the ANSI value of the character, ANSI is defined as a 8-bit
value.

AscW returns the Unicode value of the character, Unicode is defined as an
16-bit code point (in .NET).

I would create a BinaryWriter or a StreamWriter over the MemoryStream with
the proper encoding set, and call BinaryWriter.Write(Char) or
StreamWriter.Write(Char).

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top