[RESOLVED] Binary Writer (complete string)
I want to write a string into a binary file.
The length of the string is 22
position 1036
Write name in that chain, the length of the name varies but is always between a length of 22.
As I can fill the remaining length of the string with blank spaces?
The empty spaces in hex is "00"
Thanks in advance.
Re: Binary Writer (complete string)
No absolutely sure about this, but I think you'll find that '00' is effectively a nul or chr$(0) and VB will treat that as end of string - I may be wrong
Pad out with spaces chr$(32) is my best advice
Re: Binary Writer (complete string)
I do not think I explained well
Dim s as string
TextBox1.MaxLength = 22
Textbox1.text = "ANTONIO" 'length 7
s = textbox1.text & "00000000000000"
The problem is that the name may vary in size
How to determine the number of "0" to add?
Re: Binary Writer (complete string)
At a quick guess:
Code:
s = textbox1.Text & new String("0", Math.Max(0, 22 - textbox1.Text.Length))
Re: Binary Writer (complete string)
Code:
'test data
TextBox1.Text = "Dewayne"
Dim s As String = TextBox1.Text.PadRight(22, "0"c)
Debug.WriteLine(s)
Debug.WriteLine(s.Length)
Re: Binary Writer (complete string)
Re: [RESOLVED] Binary Writer (complete string)
Oo good find db, I have not used that method myself.
Re: [RESOLVED] Binary Writer (complete string)
Ummmm.... I could be wrong about this but.... won't "0"c give you 0? Which isn't the same as the hex value of 0. "0"c will give you the CHARACTER "0" ... which is hex 2F...
-tg
Re: [RESOLVED] Binary Writer (complete string)
Quote:
Originally Posted by
techgnome
Ummmm.... I could be wrong about this but.... won't "0"c give you 0? Which isn't the same as the hex value of 0. "0"c will give you the CHARACTER "0" ... which is hex 2F...
-tg
I wasn't sure what the fill character was supposed to be either.
Re: [RESOLVED] Binary Writer (complete string)
Ok, I was jsut checking... thought maybe you knew something I didn't... according to the OP, "The empty spaces in hex is "00"" ... which means it's null padded... which is always a joy in VB... :P
-tg