467,134 Members | 1,092 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,134 developers. It's quick & easy.

Problem reading Chr(0) from random file...

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
Jul 21 '05 #1
  • viewed: 1534
Share:
11 Replies
Venkatarajan <Ve**********@discussions.microsoft.com> wrote:
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.


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
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

"Jon Skeet [C# MVP]" wrote:
Venkatarajan <Ve**********@discussions.microsoft.com> wrote:
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.


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3
Venki <Ve***@discussions.microsoft.com> wrote:
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


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4
I tried it in Command Window. It gives the same result. Help me to solve this
issue.

Regards,
Venkatarajan

"Jon Skeet [C# MVP]" wrote:
Venki <Ve***@discussions.microsoft.com> wrote:
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


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #5
Venki <Ve***@discussions.microsoft.com> wrote:
I tried it in Command Window. It gives the same result. Help me to solve this
issue.


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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #6
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

"Jon Skeet [C# MVP]" wrote:
Venki <Ve***@discussions.microsoft.com> wrote:
I tried it in Command Window. It gives the same result. Help me to solve this
issue.


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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #7
Venki <Ve***@discussions.microsoft.com> wrote:
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.


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #8
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

"Jon Skeet [C# MVP]" wrote:
Venki <Ve***@discussions.microsoft.com> wrote:
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.


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #9
Venki <Ve***@discussions.microsoft.com> wrote:
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.


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #10
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

"Jon Skeet [C# MVP]" wrote:
Venki <Ve***@discussions.microsoft.com> wrote:
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.


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #11
Venki <Ve***@discussions.microsoft.com> wrote:
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.


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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by David Gray | last post: by
6 posts views Thread by Dietrich Epp | last post: by
3 posts views Thread by Tim::.. | last post: by
2 posts views Thread by Bruce Wiebe | last post: by
9 posts views Thread by jeff M via .NET 247 | last post: by
reply views Thread by Tim Wagaman | last post: by
11 posts views Thread by Venkatarajan | last post: by
10 posts views Thread by tvin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.