|
-
Dec 2nd, 2011, 05:28 AM
#1
Thread Starter
Member
[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.
Last edited by sevito; Dec 2nd, 2011 at 07:51 AM.
-
Dec 2nd, 2011, 06:05 AM
#2
Member
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
-
Dec 2nd, 2011, 07:15 AM
#3
Thread Starter
Member
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?
-
Dec 2nd, 2011, 07:38 AM
#4
Re: Binary Writer (complete string)
At a quick guess:
Code:
s = textbox1.Text & new String("0", Math.Max(0, 22 - textbox1.Text.Length))
-
Dec 2nd, 2011, 07:48 AM
#5
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)
-
Dec 2nd, 2011, 07:51 AM
#6
Thread Starter
Member
Re: Binary Writer (complete string)
-
Dec 2nd, 2011, 08:05 AM
#7
Re: [RESOLVED] Binary Writer (complete string)
Oo good find db, I have not used that method myself.
-
Dec 2nd, 2011, 08:11 AM
#8
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
-
Dec 2nd, 2011, 08:14 AM
#9
Re: [RESOLVED] Binary Writer (complete string)
 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.
-
Dec 2nd, 2011, 08:50 AM
#10
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|