473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Null Terminated ASCII String from a File Stream.

I need to read a null terminated ASCII string from a FileStream. How can I
do that? I know that with FileStream.ReadByte, I can read until I get a
byte == 0 but how can I convert a single byte to a character? Is there a
way to do this easier?

Nov 16 '05 #1
3 8540
Michel,

I would take the FileStream and pass it to a StreamReader, along with
the return value from the static property ASCII on the Encoding class (found
in System.Text). Once you have that, you can just call ReadLine on the
stream reader, and it will allow you to read the contents line by line.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Michel Racicot" <mi*********************@cgi.com> wrote in message
news:el**************@TK2MSFTNGP10.phx.gbl...
I need to read a null terminated ASCII string from a FileStream. How can I
do that? I know that with FileStream.ReadByte, I can read until I get a
byte == 0 but how can I convert a single byte to a character? Is there a
way to do this easier?

Nov 16 '05 #2
Kind of, thank you for the Info... But the file is binary (but includes null
terminated strings at certain offsets).

So far, I use the BinaryReader class to find the offsets of the strings, I
wanted to know if I could also use BinaryReader to read the strings
themselves.

Any idea?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Oj**************@TK2MSFTNGP11.phx.gbl...
Michel,

I would take the FileStream and pass it to a StreamReader, along with
the return value from the static property ASCII on the Encoding class (found in System.Text). Once you have that, you can just call ReadLine on the
stream reader, and it will allow you to read the contents line by line.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Michel Racicot" <mi*********************@cgi.com> wrote in message
news:el**************@TK2MSFTNGP10.phx.gbl...
I need to read a null terminated ASCII string from a FileStream. How can I do that? I know that with FileStream.ReadByte, I can read until I get a
byte == 0 but how can I convert a single byte to a character? Is there a way to do this easier?


Nov 16 '05 #3


"Michel Racicot" wrote:
Kind of, thank you for the Info... But the file is binary (but includes null
terminated strings at certain offsets).

So far, I use the BinaryReader class to find the offsets of the strings, I
wanted to know if I could also use BinaryReader to read the strings
themselves.
you use the BinaryReader to read in a byte[], then pass that to the
appropriate System.Text.Encoding class to convert to a string.

Any idea?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Oj**************@TK2MSFTNGP11.phx.gbl...
Michel,

I would take the FileStream and pass it to a StreamReader, along with
the return value from the static property ASCII on the Encoding class

(found
in System.Text). Once you have that, you can just call ReadLine on the
stream reader, and it will allow you to read the contents line by line.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Michel Racicot" <mi*********************@cgi.com> wrote in message
news:el**************@TK2MSFTNGP10.phx.gbl...
I need to read a null terminated ASCII string from a FileStream. How can I do that? I know that with FileStream.ReadByte, I can read until I get a
byte == 0 but how can I convert a single byte to a character? Is there a way to do this easier?



Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: David Mathog | last post by:
Every so often one of my fgets() based programs encounters an input file containing embedded nulls. fgets is happy to read these but the embedded nulls subsequently cause problems elsewhere in...
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
2
by: Martín Marconcini | last post by:
Hello there, I'm writting (or trying to) a Console Application in C#. I has to be console. I remember back in the old days of Cobol (Unisys), Clipper and even Basic, I used to use a program...
3
by: Asha | last post by:
greetings, i have some questions below, what are the differences between private string _strVal = string.Empty; and _strVal = null; does the string.Empty; allocate memory for it? how about...
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
3
by: Carlo Stonebanks | last post by:
I need to read a binary file which has mixed data types embedded in it. Fixed length strings, 16-bit integers and zero (null) terminated ASCII strings. (akak ASCIIZ) The first two types are no...
12
by: semut | last post by:
Given that the string is of null terminated type. What could be the possible causes (by experience) the string to have no null terminated and cause buffer overflow later. I know it is quite broad,...
14
by: mast2as | last post by:
Hi everyone, I am trying to implement some specs which specify that an array of parameter is passed to a function as a pointer to an array terminated by a NULL chatacter. That seemed fairly easy...
5
by: ssylee | last post by:
If I'm being supplied with a char* that is not null-terminated, is it impossible to transform it into a null terminated char* with only abstract information about the char* information?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.