Groups | Blog | Home
all groups > dotnet general > november 2004 >

dotnet general : Problem reading Chr(0) from random file...


Venkatarajan
11/29/2004 11:29:02 PM
hai,
At present I'm facing a strange problem. We are converting a project from
VB to .NET
One record contains Chr(0). Let the record be of length 1800. In the 50th
byte of a record a chr(0) is there.
While I use VB to read it's giving all 1800 bytes. But when I converted my
VB to VB.NET, after the 49th byte all the bytes are truncating. I have to
solve this issue to proceed further. I hope the experts around here can solve
my problem.
I'm using the random file and using a structure of length 1800 bytes.
Following is the code I use

Public Structure StudentRCDetails
<VBFixedString(1800)> Dim lsData As String
End Structure

Dim lStructDetails As StudentRCDetails

FileOpen(liKeyFileNum, lsFilePath, OpenMode.Binary, , OpenShare.Shared, 1800)
FileGet(liKeyFileNum, lStructDetails , Integer.Parse(lsStudentID))
FileClose(liKeyFileNum)


I'm getting only a part of a string. ie. till the Chr(0). After, all the
datas are discarded.
I tried with opening in Random mode also. The result is same for both the
cases.
Please help me in this issue. It's urgent

regards,
Venkatarajan

Venki
11/30/2004 12:07:07 AM
Hai Jon,
I tried to print it out in the debugger?. Let assume the string be
"Venkat" & Chr(0) & "rajan".
When I tried to print it in the debugger it shows as
"Venkat
When try to extract character by character, it shows me a error.
Not even the terminating quotes.

Help me out

Regards,
Venkatarajan

[quoted text, click to view]
Venki
11/30/2004 1:19:03 AM
I tried it in Command Window. It gives the same result. Help me to solve this
issue.

Regards,
Venkatarajan

[quoted text, click to view]
Venki
11/30/2004 2:43:05 AM
hai jon,
It's working fine when I tried with Console Application. But when did the
same with Web Services or Windows application the string is getting
truncated. Please help me in this issue.
Dim str1 As String
str1 = "Venkat" & Chr(0) & "Rajan"
Console.WriteLine(str1)
Console.ReadLine()
It gave Venkat Rajan in Console Application.

Dim str1 As String
str1 = "Venkat" & Chr(0) & "Rajan"
msgbox(str1)
When I used a windows Application , it showed me only Venkat.
Thanks in Advance.

Regards,
Venkatarajan

[quoted text, click to view]
Venki
11/30/2004 3:23:04 AM
Hai Jon,
See my first post. I'm getting the Structure of length 1800 bytes. When I
tried to read it from the file, the character what I'm getting is terminated
when it reaches the null string. I have solve this issue.
Thanks in advance

Regards,
Venkatarajan

[quoted text, click to view]
Jon Skeet [C# MVP]
11/30/2004 7:46:35 AM
[quoted text, click to view]

Are you *absolutely sure* that it's actually being truncated? How are
you examining the string? If it's in the debugger, try printing out the
string - you may well find that the rest of the data is there, it's
just not being shown in the debugger.

(I would be more confident about this if you were using standard .NET
IO classes - I'm not familiar with the VB functions you're using.)

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Jon Skeet [C# MVP]
11/30/2004 8:54:22 AM
[quoted text, click to view]

Don't print it out in the debugger - print it out in a console window.
Basically, don't trust the debugger when it comes to strings, until you
know exactly how it handles them.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Jon Skeet [C# MVP]
11/30/2004 10:26:19 AM
[quoted text, click to view]

Don't try it in the command window, try it in the console - using
Console.WriteLine - as I suggested before.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Jon Skeet [C# MVP]
11/30/2004 10:48:22 AM
[quoted text, click to view]

That's just because message box will truncate strings. The string
itself is fine.

If you want to get rid of the nul characters, use String.Replace and
replace them with whatever you want (eg space).

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Jon Skeet [C# MVP]
11/30/2004 12:41:05 PM
[quoted text, click to view]

I'm still not convinced it *is* actually being terminated - have you
tried printing out the string *to the console* (not the debugger, not
the command window, not a web page, not a message box) after reading
it?

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Venki
11/30/2004 8:55:02 PM
Hai Jon,
As you said I tried to print it in the console. It's displaying
correctly. But when tried to do some calculations based on the string, I'm
unable to get the whole part of the string.
Thanks in advance
regards,
Venkatarajan

[quoted text, click to view]
Jon Skeet [C# MVP]
12/1/2004 8:46:28 AM
[quoted text, click to view]

You should be able to, just using the standard .NET string access
methods. What's failing for you?

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
AddThis Social Bookmark Button