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 9131387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:07:59+00:00 2026-06-17T08:07:59+00:00

I am using the following function to convert binary data to text: public string

  • 0

I am using the following function to convert binary data to text:

public string BinaryToText(byte[] data)
{
     MemoryStream stream = new MemoryStream(data);
     StreamReader reader = new StreamReader(stream, encoding.UTF8);
     string text = reader.ReadTod();
     return text;
}

But I get an OutOfMemoryException for 30Mb data.

How can I solve this problem and convert data larger than 100Mb, using this or any better method?

  • 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-06-17T08:08:00+00:00Added an answer on June 17, 2026 at 8:08 am

    Try this instead:

    public string BinaryToText(byte[] data)
    {
        return Encoding.UTF8.GetString(data);
    }
    

    It will consume less memory. If it still runs out of memory, you’ll need to read it in chunks – but how you are using the data will determine if that is possible. What are you doing with the returned string?

    Also I will reiterate my earlier question: Is the input data really UTF8 data?

    If you can handle the data being returned as multiple strings, you can do something like this:

    public IEnumerable<string> BinaryToStrings(byte[] data, int maxStringLength)
    {
        var buffer = new char[maxStringLength];
    
        using (MemoryStream stream = new MemoryStream(data))
        using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
        {
            while (true)
            {
                int count = reader.Read(buffer, 0, maxStringLength);
    
                if (count == 0)
                {
                    break;
                }
    
                yield return new string(buffer, 0, count);
            }
        }
    }
    

    Then you can call that in a foreach loop like so:

    foreach (string chunk in BinaryToStrings(data, 1024))
    {
        // Do something with 'chunk'...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following function to encrypt a string: public string Encrypt(string stringToEncrypt,
I am trying to convert text to wave file using following function. It works
I have the following function that will convert a string into a numeric data
I am using the following function to Convert a String variable to a Date.
I want to print an integer number in binary mode using following function: #include
Using the following code: Function GetSetting(Of T)(ByVal SettingName As String, ByRef DefaultVal As T)
I am using following code to convert string to sha1 string but i am
I am trying to convert dips to pixels using the following function. I’ve tried
I have the following function to convert a byte array of pixels into an
I'm using the following geocoding function to convert a textual address into latitude and

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.