Bogdan
4th November 2021, 12:05
Hi,
I have a string I must replace in a binary file. In the binary file the original string has a fixed length, but the string I am replacing with may be shorter and I must add NULL character up to the required length.
Please help me with this, I didn't find a way to do insert a NULL character. The hexa code for NULL character is 00.
Thank you

mark_h
4th November 2021, 13:46
Any specific reason why you can't just use a space? Or chr$(0)? I typically always used spaces, and never really used binary files.

OmeLuuk
4th November 2021, 14:28
As far as I know you will only need one 0x00 character (chr$(0) indeed) to close the string (where the first 0x00 will mean "end of string".

BTW note that when using MB strings field the length may be different when a MB character is in the string (uses 4 or so bytes instead of 1).

Bogdan
4th November 2021, 15:41
Hi Mark,
I can use space also, but the generated file is used by a marking machine and if I use blanks the marking head is traveling up to the end of line without doing any job.
If there is NULL, as soon as one line is finished, the second one is started.
Thank you very much for your help

Bogdan
4th November 2021, 15:43
Hi OmeLuuk,
I tried with chr$(0) but I get Euro sign :) instead of NULL; shalI I use chr$(0000)? I will try.
Thank you very much for your help

OmeLuuk
4th November 2021, 15:59
Can you post part of the code where you want to put the 0x00 in the string? Apparently you us a "different" / MBS codepage / TSS table where the euro sign is added later... Can you try to add "^A" Control-A? Or maybe try mb.char(0)?

Bogdan
4th November 2021, 16:02
Hi guys,
seq.write is doing the job; if the replacement string(buffer) is shorter than the replaced bytes, the remainings bytes are filled with NULL character.
Thank you very much for your answers,
It's quite a nice function, seq.write :)