Hey,
When I was messing around with VB.net with a BinaryReader to read a string, I only saw an option to read a 7 character string, and no others.
Would there be an option to just read a null terminated string?, Because I can't seem to find it.
Cheers,
Matsy
Important information: this site is currently scheduled to go offline indefinitely by end of the year.
Read String VB.net
I think the VB.net Binary String Reader reads 1 byte before the string and uses that for the string length.
I don't think I have even looked I've always just used something like this
dim test as string
dim byter as byte = 1
....
While byter <> 0
byter = bread.ReadByte
test+= Chr(byter)
End While
I'd hope there was something built in, but laziness had always resorted in me using that above.
I don't think I have even looked I've always just used something like this
dim test as string
dim byter as byte = 1
....
While byter <> 0
byter = bread.ReadByte
test+= Chr(byter)
End While
I'd hope there was something built in, but laziness had always resorted in me using that above.
also very slow too
i don't use vb.net but c# equiv is
with a FileStream or BinaryReader, i use filestreams
This works out better because its easier to change encodings. For say UTF8 or UTF16LE/BE.
VB.NET example
i don't use vb.net but c# equiv is
with a FileStream or BinaryReader, i use filestreams
Code: Select all
byte[] bytestring = new byte[size];
fs.read(bytestring);
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
string mystring = encoding.GetString(bytestring);
VB.NET example
Code: Select all
Dim dBytes As Byte() = ...
Dim str As String
Dim enc As New System.Text.ASCIIEncoding()
str = enc.GetString(dBytes)
"By nature men are alike. Through practice they have become far apart." Confucius (Analect 17:2)