Last post Jul 01, 2008 06:26 PM by Svante
Jul 01, 2008 05:36 PM|jkits|LINK
I am writing some data to a DAT file using filestream at a particular positions. But when when I open the DAT file in textpad I am seeing NON Ascii character like NUL(^@=0=0x0). How do I prevent them from getting in to the file.
For example, if I start writing "Joe" starting at position 10. Then from position 0..9 I am seeing these NULs. Here is my code.
//set the position like below.
Is there some other function I need to use to avaoid the NULs to get to the DAT file like sprintf(not sure if there is one in C#)
Thanks in advance
Jul 01, 2008 05:51 PM|Svante|LINK
I start writing "Joe" starting at position 10. Then from position 0..9 I am seeing these NULs
Right. What did you expect to find in position 0..8 (not 9 - you're skipping to position 9, the 10th byte of the file, with your code) when you do not write there? You're creating a new file, and then skipping forward 9 bytes and start writing the 10th byte.
What else would you want the system to put in the positions you do not write?
Jul 01, 2008 06:21 PM|jkits|LINK
I want to make sure if thats the correct behaviour since NUL is NON ascii. Is there a way to replace the NUL by a space?
Jul 01, 2008 06:26 PM|Svante|LINK
Is there a way to replace the NUL by a space?
Certainly - by writing a space in the file in those positions. If you'd like to have 10 space to the left of string 's', you can write s.PadLeft(s.Length + 10); Then you write the entire result to the file, starting at position zero.