MemoryBlock to String again

Sorry but I am reading previous posts on this topic to no avail.

I am trying to get some ASCII text into a MemoryBlock, then back out again into string.
The purpose of the exercise is to experiment with encryption algorithms.
Here is some test code. The problem is that the TextArea will display “question mark in a diamond” character rather than interpreting the character code as EndOfLine.

BTW looking at the memory block in the debugger I can see that the end-of-line characters are &h0A, which is what I would expect for ASCII. So I think the problem is only in the conversion back to string.

Dim m As MemoryBlock
Dim n,i As Integer
Dim b As Uint8
Dim m_e As New MemoryBlock(131072)
Dim m_d As New MemoryBlock(131072)

// encryption
// s as passed in displays properly in a TextArea
s = ConvertEncoding(s,Encodings.ASCII) // presume it was UTF-8
m = s
n = m.Size - 1
For i = 0 to n
b = m.UInt8Value(i)
// do something to b here
m_e.UInt8Value(i) = b
Next

// decryption
n = m_e.Size - 1
For i = 0 to n
b = m_e.UInt8Value(i)
// do something to b here
m_d.UInt8Value(i) = b
Next
s = m_d
s = ConvertEncoding(s,Encodings.UTF8) // presumably TextArea prefers UTF-8 (?)
TextArea1.Text = s
// oops nasty question-mark-in-a-diamond character has replaced all of the EndOfLine characters!

Change the EndOfLine values before assigning s to TextArea1.

Using ReplaceLineEndings (for example)…

Figured it out. This works. I changed the last ConvertEncoding into DefineEncoding.

Dim m As MemoryBlock
Dim n,i As Integer
Dim b As Uint8
Dim m_e As New MemoryBlock(131072)
Dim m_d As New MemoryBlock(131072)

// encryption
// s as passed in displays properly in a TextArea
s = ConvertEncoding(s,Encodings.ASCII) // presume it was UTF-8
m = s
n = m.Size - 1
For i = 0 to n
b = m.UInt8Value(i)

// do something to b here
m_e.UInt8Value(i) = b

Next

// decryption
n = m_e.Size - 1
For i = 0 to n
b = m_e.UInt8Value(i)
// do something to b here
m_d.UInt8Value(i) = b
Next
s = m_d
s = DefineEncoding(s,Encodings.UTF8) // presumably TextArea prefers UTF-8 (?)
TextArea1.Text = s // display it with diamonds+question marks

diamond+question mark
Do you know what this character stands for ?
It is the replacement character: a character that is used when the one asked is unknow in the current font.