Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Null characters in text file-ascii value 0

Status
Not open for further replies.

olichap

Programmer
Mar 20, 2001
389
US
When I write a fixed length string to a text file (using a user defined type) I sometimes do not have all variables populated. In the LSET derived string that I then write to file any UDT variables not populated will be full of Null characters (ascii-0).

My question is this:

Does VB write the characters as a Null or a space (ascii-32)? When I read the string FROM the text file into a variable the Null characters are substituted with strings.

Thanks,
Oliver
 
Never mind, its definitly writing the null characters to file. I guess VB just interprets these characters as spaces when they exist within a string.
 
Careful. When I would read files which contained null, LINE INPUT would drop the null characters i.e. everthing following the null was shifted to the left. Those space may be the space that followed the null, not a translation. Compare Code (Text)
Generate Sort in VB or VBScript
 
Thanks John,

That's a good thing to know. I did a test by just reading the data from the text file into a string variable, then out-putting the ascii value of each character (just to see whether VB read the values as 0 or 32). I did NOT check to see whether the string read IN was the same size as the fixed-length though.

The problem I was dealing with really related to how C/C++ reads strings. Someone else has to parse the file using a C utility. I think the Null character was being interpreted by C as the file/record termination character instead of space filler.

Oliver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top