3 Replies - 13671 Views - Last Post: 18 November 2008 - 12:30 AM Rate Topic: ***** 1 Votes

#1 imperator   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 08-November 08

How convert all bytes to string

Posted 13 November 2008 - 04:26 PM

I binary read a file and i want to convert binary to string

byte[] poleBytov = File.ReadAllBytes(cesta);
			string retazec = System.Text.ASCIIEncoding.ASCII.GetString(poleBytov);
			textBox1.AppendText(retazec);



but append me a few chars to the textbox and stop, because in the begin of the file is some signs (or chars) which represent an end of file (i think)

here is the file http://luxusny.sk/stitok.prn

I cannot convert all byte array to the string !

anyone can help me ? :blink:

This post has been edited by imperator: 13 November 2008 - 04:33 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How convert all bytes to string

#2 n8wxs   User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: How convert all bytes to string

Posted 13 November 2008 - 06:55 PM

using (FileStream fs = File.Open("c:\\temp\\stitok.prn", FileMode.Open))
{
    byte[] b = new byte[1024];

    while (fs.Read(b, 0, b.Length) > 0)
    {
         for (int i = 0; i < b.Length; i++)
              Console.Write(b[i].ToString() + " ");
     }

     Console.ReadKey();
}


This will print each byte as a decimal integer, probably not what you want.

This post has been edited by n8wxs: 13 November 2008 - 06:56 PM

Was This Post Helpful? 0
  • +
  • -

#3 imperator   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 08-November 08

Re: How convert all bytes to string

Posted 16 November 2008 - 05:05 AM

hm.. no because i want to read this file to string...
Was This Post Helpful? 0
  • +
  • -

#4 n8wxs   User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: How convert all bytes to string

Posted 18 November 2008 - 12:30 AM

Well the data file you are using has non-ASCII-printable bytes in it so converting directly to a string isn't going to work. For eample nulls - zeros.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1