MemoryBlock Conversions

I’ve started with a shared example from MemoryBlock, then I expand it a bit and there comes a strange thing !

Original example(s):

Dim s As String = "abcde" Dim mb As MemoryBlock mb = s MsgBox(Str(mb.Size)) //displays 5
Returns 5: OK.

Dim a As String a = mb
Nice !

MsgBox(mb)  //displays "abcde"

Works as expected !

My code:

[code]Sub Action() Handles Action
Dim s As String = “abcde”
Dim mb As MemoryBlock
Dim mbStr As String

// Store the string into a MemoryBlock
mb = s

// Convert the MemoryBlock to a String
mbStr = mb

// Report the data
MsgBox “MemoryBlock Properties” + EndOfLine + EndOfLine +_
“Contents: " + mbStr + EndOfLine + _
“Size (in bytes): " + Format(mb.Size,”###,###”)
End Sub[/code]

This code returns the expected information excepted for the EndOfLine in the Contents line: I got the Replacing Character !

And I modified the MsgBox code to:

MsgBox "MemoryBlock Properties" + EndOfLine + EndOfLine +_ "Size (in bytes): " + Format(mb.Size,"###,###") + mbStr + EndOfLine + _ "Contents: "

And I get the same behavior. I even add a second EndOfLine (the second MsgBox line): the only difference is that I get two times the Replacement Character instead of two EndOfLine.

Of course, as is, I do not care at all about this strange behavior. But this annoy me elsewhere in my code where I use this transformation technic.

El Capitan 10.11.6
Xojo 2016r1

Hmm. The EndOfLine character changed in Cocoa. Perhaps Msgbox wants the old one? I don’t recall the details off the top of my head, but if that is truly the case, a bug report would be in order.

Try

msgbox "MemoryBlock properties:" + EndOfLine.Unix + ...

Check your encodings since a memoryblock doesn’t have one and encoded string + unencoded bytes = unencoded bytes

Thanks Norman.

To resolve this trouble, I will do that.

This works fine (as I expected: the properties are in 2 lines):

[code]
Dim s As String = “abcde”
Dim mb As MemoryBlock
Dim mbStr As String

// Store the string into a MemoryBlock
mb = s

// Convert the MemoryBlock to a String
mbStr = mb

mbStr = DefineEncoding(mbStr, Encodings.UTF8)

// Report the data
MsgBox “MemoryBlock Properties” + EndOfLine + EndOfLine +_
“Contents: " + mbStr + EndOfLine + _
“Size (in bytes): " + Format(mb.Size,”###,###”)[/code]

Now, I have to solve my original problem.