Remove null characters from memoryblock

All . . . I may be way off, but . . . . . .

I’ve been working with excelWriter2.rbp which has a couple of errors. It appears that if I could remove the null (“0000”) characters from a memoryblock it would work.

When converting to a string a null character seems to stop the conversion.

Any ideas?

What is your code?

Memoryblock.StringValue should handle nulls just fine. How are you doing the conversion?

the conversion is being done with a as string = mb as memoryblock.

A quick test shows that a string containing several chr(0) does convert back and forth with no loss.

Have you checked MB.Size ? Does it match the length of the data you expect ? Could the issue be when the data is loaded in the MB ?

Note that a string with null bytes will not display well, but the string is still intact. How do you determine that there is a problem with it?

I’ve looked at the memoryblock in the IDE. Everything is being entered into the memoryblock by a binary stream, but there are many null (“0000”) entries. When the program converts the memoryblock text it seems to stop at the first null entry and the rest is ignored.

When converted to text this is all that shows up:

Watson Test

The memoryblock looks like this:

memoryBlock image

Ok, so if I ignore the memoryblock and just concatenate a string I have the same problem. When I look at the string in binary it’s just like the memory block ([urlurl=http://www.circleconsulting.us/gym/memoryBlock.png]string in binary[/url]), but the string only shows up to the first “0000” and ignores the rest:

Watson Test

So, it’s not the memory block, it’s the difference between the binary and text.

Ok, so if I ignore the memoryblock and just concatenate a string I have the same problem. When I look at the string in binary it’s just like the memory block (string in binary), but the string only shows up to the first “0000” and ignores the rest:

Watson Test

So, it’s not the memory block, it’s the difference between the binary and text.

Got a small example that shows what it is you’re trying to achieve ?

Thats an awful lot of zeroes.
It does look as if what you have there isnt a displayable string per se, but a number of fixed width fields.

Try changing the zeroes to spaces with this:

for x as integer = 0 to mb.size-1
if mb.byte(x) = 0 then mb.byte(x) = 32
next

then copy to your string.
You might then replace all instances of <spcspcspcspcspc…etc> with nothing

Thanks Jeff . . . That did it. I used the tab instead (mb.byte(x) = 9) so I could remove all tabs from the final output string.

Norman … excelwriter2.rbp creates an xml file for uploading to excel, so:

Watson Test Second Row