Re: Encoding... sigh.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 02/11/04


Date: Wed, 11 Feb 2004 16:25:39 -0000

C# Learner <csharp@learner.here> wrote:
> >Then just read the content from the stream, and don't try to convert it
> >into a string.
>
> But I need to eventually convert this content into an array of bytes
> (to be sent off to another socket). I really can't have decoding
> happening here. :-(

Then why were you trying to read it into a string? Just read it into an
array of bytes. You can use MemoryStream to make that easier for you -
just read a block at a time, writing the contents of the block to the
MemoryStream, and then call ToArray at the end.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: Reading 8 bit chars off a stream
    ... You might want to consider a MemoryStream instead of a Listto ... stream internally, and if the device isn't going to offer up anything past ... data packet are null terminted. ... Encoding to get the string. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: DES Key & IV
    ... public String EncryptData(String data, ... string strResult; //Return Result ... // mOut is the output stream. ... MemoryStream mStream = new MemoryStream; ...
    (microsoft.public.dotnet.security)
  • Figured it out, can you make this more efficient? Re: Conversion to C#, but how do I response.write
    ... a byte array and saving it using a FileStream object. ... byte array to a string using System.Text.Encoding.UTF8 and response.write ... However, I am new to the MemoryStream, and am having trouble converting my ... For each file in a named directory, make a "FileSystemItem" element ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Retrieve posted information
    ... the only diffrence is that i decoded the string using UTF8 decoder which is ... ' Find number of bytes in stream. ... Dim strLen As Long = CInt ... ' Read stream into byte array. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: EBCDIC to byte array
    ... string in a webrequest, so I convert my strings to a byte array, byte array ... to a stream and then I do a mainframe http request. ... an EBCDIC stream, converts to byte array and then to EBCDIC string. ...
    (microsoft.public.dotnet.framework)