Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5960845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:52:56+00:00 2026-05-22T18:52:56+00:00

I have a stream that gets converted into a byte array. I then take

  • 0

I have a stream that gets converted into a byte array.

I then take that bye array and turn it into a string.

When I try to turn that string back into a byte array it is not correct…see the code below.

     private void Parse(Stream stream, Encoding encoding)
     {
        // Read the stream into a byte array
        byte[] allData = ToByteArray(stream);

        // Copy to a string for header parsing
        string allContent = encoding.GetString(allData);

        //This does not convert back right - just for demo purposes, not how the code is used
        allData = encoding.GetBytes(allContent);
    }

    private byte[] ToByteArray(Stream stream)
    {
        byte[] buffer = new byte[32768];
        using (MemoryStream ms = new MemoryStream())
        {
            while (true)
            {
                int read = stream.Read(buffer, 0, buffer.Length);
                if (read <= 0)
                    return ms.ToArray();
                ms.Write(buffer, 0, read);
            }
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:52:57+00:00Added an answer on May 22, 2026 at 6:52 pm

    Without having more information, I’m quite certain that this is a text encoding issue. Most likely, the text encoding in the stream is different than the encoding specified as your parameter. This will result in different values at the byte level.

    Here’s a few good articles that explains why you’re seeing what you’re seeing.

    • The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
    • How to Determine Text File Encoding
    • General questions, relating to UTF or Encoding Form
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fair few images that I'm loading into a ListBox in my
I have some pages that I want to save the PRINT version of the
I have an HTTP Module that I use to clean up the JSON returned
I have a function that takes an opened file object file and writes data
I have a xts object (stock price time series) that is comprised of intraday
I'm running into problems on the WP7 with MediaElement downloading a 128kbps mp3 stream
currently I have a disfigured avi file that a program of mine creates. I
I have edited this question to make it easier to understand. I have an
I'm making an MSN client in PHP. I have this code, which connects to
I have Java webserver (no standard software ... self written) . Everything seems to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.