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

  • SEARCH
  • Home
  • 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 6748143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:31:49+00:00 2026-05-26T12:31:49+00:00

These days I’m facing a problem with encoding string from an array of byte.

  • 0

These days I’m facing a problem with encoding string from an array of byte.
I use a socket to receive the data from server to a buffer, then I create a MemoryStream to read data from this buffer to a tempBuffer with a fixed length 30 to later GetString from tempBuffer.

byte tempBuff = new byte[30];
streamReader.Read(tempBuff, 0, 30);
string moTaSkill = Encoding.UTF8.GetString(tempBuff);

The I use a textBox to display this string as below:

tbSkill.Text = moTaSkill;

It always display wrong on the text box:

  1. When debug I see moTaSkill = “SKill of the hero”
  2. When display on the textBox it just “Skill of” or sometimes “Skill ” or “Skill of the”

I tried to create the tempBuffer with the length equals the length of string I will receive. But no success.

Can any one tell me some solution to fix it?

  • 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-26T12:31:49+00:00Added an answer on May 26, 2026 at 12:31 pm

    Two problems. You are forgetting to pay attention to the return value of the Read() call. It tells you how many actual bytes got copied into tempBuf. Which you should then use in the GetString() method so that you can avoid converting zeros.

    Second problem is that a TCP connection provides a network stream, not a packet. It is quite unpredictable how many bytes you’ll get for each Read() call. Again, the return value tells you this. It will only match the number of bytes that were transmitted by the server by accident. You need to keep calling Read() until you get them all. Chief problem with that is that you don’t necessarily know when the reading is done. The server will need to pass some extra data so that the receiver knows. Like sending the string length first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

These days I am importing quite a lot of databases from my server and
Web-Applications these days make extensive use of Javascript, for example various Google Products like
Is there any performance to be gained these days from compiling java to native
Server virtualization is a big thing these days, so I'm tasked at work to
These days I am interested in learning F#, and would like to use it
These days, I use Flex & Bison generated some codes to develop a SQL-parser
There are many applications for Windows these days that don't use native windows controls,
These days I am approaching MPI world. I am willing to use Boost MPI
What is the normal wait time these days for iPad apps to move from
I'm learning these days how to use ant to run automated test folowing this

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.