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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String variable has no closing quote - why?

Status
Not open for further replies.

Sypher2

Programmer
Oct 3, 2001
160
US
I am currently reading information from a binary file. Whenever I do a ReadChars on the binary reader, I do not get a closing quote.

For example (br is the instantiated BinaryReader):

Code:
Dim tData1 As Int32 = br.ReadInt32 [COLOR=green]'Works[/color]
Dim tData2 As String = br.ReadChars(15) [COLOR=green]'Get 15 characters[/color]

tData1 will hold correct data.
tData2 will have something like "Example

There is no closing quote to the variable. This is very strange and causes problems later on when I try to see if this variable is equal to something else. It will always fail... "Example" <> "Example

Anyone know what's going on here?

Thanks
 
No the debug window shows:
Code:
Example

However if I hover the mouse over the variable I get:
Code:
"Example

Then when I look at the debug window after closing the app it shows:
Code:
ExampleThe program '[blah blah]' has exited with code 0 (0x0).

Even with writeline it's not doing a CRLF. Maybe I need to add that to the end of the string?
 
There are several parts where I use ReadChars. Sometimes it's Int16 afterward. Sometimes Int32. Sometimes another ReadChars.
 
Is it always 15 characters? You aren't by chance trying to read 1 too many characters and winding up with a strange byte in there?

You could also try iterrating through the char array that you read in to populate a string builder.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Yes, I tried iterating through the char array and make a string builder. That worked and I insert it into a database, but then when I read the data back from the database from a different application, I get the same result.

When I do a DataReader.GetString, it shows "Example when I hover the mouse over the variable.
 
It's ASCII code 0 (zero) which is a null.

Even though it is 15 characters, there may fewer than that with any real character in it.

I've resorted to iterating over the char array when inserting into the DB and also interating over the char array when reading back from the DB.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top