Question Not all text is read?

The-Don

Member
Joined
Feb 10, 2011
Messages
5
Programming Experience
1-3
I have a multiline textbox which is loading from a .dat file. However, despite telling it to load all of the .dat file, it misses off the end. I it copies the first large body of text and a load of spaces that are inbetween the first and second body, but doesn't load the second body of text. Here is the code I'm using to open my file:

RichTextBox2.Text = IO.File.ReadAllText("00061530.dat")


Any ideas what is wrong?
 
Does the DAT file actually contain text? If not then you shouldn't really be trying to represent it as text. Quite possibly the file contains a null byte, which would be interpreted by .NET as a string terminator, hence nothing after that position is displayed as part of the string.
 
Does the DAT file actually contain text? If not then you shouldn't really be trying to represent it as text. Quite possibly the file contains a null byte, which would be interpreted by .NET as a string terminator, hence nothing after that position is displayed as part of the string.

Yeah it does contain a mixture of text and null bytes. How would I display the null bytes and texts together? Is it possible? Programs like notepad ++ do show the entire file including null bytes.
 
You should find that the String object does contain all the data but nothing after the first null character will be displayed. You can test that theory by checking the IndexOf the ControlChars.NullChar and the Length of the String. In that case, you would presumably be able to Replace the null characters with something else and have the lot display.
 
You should find that the String object does contain all the data but nothing after the first null character will be displayed. You can test that theory by checking the IndexOf the ControlChars.NullChar and the Length of the String. In that case, you would presumably be able to Replace the null characters with something else and have the lot display.

And how exactly would one go about doing that? Your conclusion was correct, the string proved that the data was there but wasn't displayed after the null value. What code do you personally recommend to replace the null value, as I have seen a wide variety of different solutions. Thanks again for your help, you're an incredibly talented coder.
 
Back
Top