# MemoryBlock Conversions

**URL:** <https://forum.xojo.com/t/memoryblock-conversions/35763>\
**Category:** General\
**Created:** [January 27, 2017, 7:06pm UTC](https://forum.xojo.com/t/memoryblock-conversions/35763 "2017-01-27T19:06:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [January 27, 2017, 7:06pm UTC](https://forum.xojo.com/t/memoryblock-conversions/35763/1 "2017-01-27T19:06:34Z")

</div>

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 !

```auto
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

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [January 27, 2017, 8:23pm UTC](https://forum.xojo.com/t/memoryblock-conversions/35763/2 "2017-01-27T20:23:49Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [January 27, 2017, 8:48pm UTC](https://forum.xojo.com/t/memoryblock-conversions/35763/3 "2017-01-27T20:48:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [January 27, 2017, 9:38pm UTC](https://forum.xojo.com/t/memoryblock-conversions/35763/4 "2017-01-27T21:38:59Z")

</div>

Thanks Norman.

To resolve this trouble, I will do that.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [January 28, 2017, 9:01am UTC](https://forum.xojo.com/t/memoryblock-conversions/35763/5 "2017-01-28T09:01:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:37pm UTC](https://forum.xojo.com/t/memoryblock-conversions/35763/6 "2020-10-29T18:37:56Z")

</div>


