WebTextArea - Append fails due to encoding

In a Web application there is a WebTextArea that receives data stored in a MySQL db field defined as TEXT. The data can be multiple lines or a single line. Whenever I have multiple lines the following error is displayed

[quote]Unhandled RuntimeException
Message: The data could not be converted to text with this encoding.
[/quote]

I have used ASCII and UTF-8 encodings and still receive that error.

my_str = my_str.DefineEncoding(Encodings.UTF8)
enc = my_str.Encoding // In debug I can verify this is now Encodings.UTF8
myWebTextArea.AppendText (my_str)

I never ran across this before. How can I provide multi line info to a WebTextArea?

Have you tried a ReplaceLineEndings on the data coming out of the Database before sending it to the WebTextArea?

I actually SPLIT the TEXT from the db into a string array. Then I loop around adding the string array data and appending EndOfLine to ensure correct encoding of EndOfLine

my_str = my_arr(0)
If UBound(my_arr) > 1 Then
  For x = 1 to UBound(my_arr) - 1
    my_str = my_str + EndOfLine + my_arr(x)
  Next
End

my_str = my_str.DefineEncoding(Encodings.UTF8)
enc = my_str.Encoding // In debug I can verify this is now Encodings.UTF8
myWebTextArea.AppendText (my_str)

As myWebTextArea.AppendText (my_str) is executed this is the full error that is posted

[quote]Unhandled RuntimeException
Message: The data could not be converted to text with this encoding.

Stack:
GenerateJSON
xojo.Data.GenerateJSON%y%x
WebResponse._Render%s%o
WebSession._HandleEvent%%oso<_HTTPServer.HTTPRequestContext>
WebSession._HandleRequest%i4%oso<_HTTPServer.HTTPRequestContext>
WebApplication._HandleHTTPRequest%%oo<_HTTPServer.HTTPRequestContext>
_HTTPServer.HTTPRequestThread.Event_Run%%o<_HTTPServer.HTTPRequestThread>
rbframework.dylib$1221
rbframework.dylib$1016
[/quote]

I have deleted and replaced the WebTextArea but I have the same results.

I did use my_str = ReplaceLineEndings(my_str, EndOfLine.OSX) and this did not resolve the problem - FYI: I used all available EndOfLine… and the same error was posted

However this approach seems problematic as this is a Web app and the type of encoding pends on the machine type

This might be an internal issue. I see GenerateJSON in the stack there, but not in your code.

I ran into encodings issues turning String into Text unless I define the encoding immediately before converting to Text. If Xojo is doing stuff internally with Text instead of String, you may be running into this very same issue just not anywhere you can control it.

Calling @Greg O’Lone

I found the character causing the problem - TM. TM is Trade Mark symbol and is part of the extended ASCII character set. Eliminating that and all is good. While this is a temporary solution providing this symbol is needed. Changing encoding to Encodings.MacRoman allows display with no error however the character is not correct.

Try replacing TM by its HTML entity :

&trade; &#153;

With some luck it will do it.

Consider this when populating a WebTextArea with multiple lines from a MySQL Text field.

Self.My_WebTextArea.Text = ReplaceLineEndings(My_RecordSet.Field("MyMultiLiineTextField").StringValue.DefineEncoding(Encodings.UTF8), EndOfLine.Windows)