URLParameter from string ToText problem

Hello, I am having trouble converting string to text for URL parameters. I have tried various re-encoding attempts but so far I have failed. Here is my problem:

  1. New Xojo Web Project
  2. Create new Open Event handler inside the Session and put this code in the Open Event:

[code] Dim s As String = URLParameter(“TestParameter”)
System.DebugLog(s)

Dim t As text
t = s.ToText
System.DebugLog(t)[/code]

  1. Run project and go to http://127.0.0.1:8080?TestParameter=hello

Expected result: Two messages in the debugLog both saying ‘hello’.
Actual result: The string is reported correctly, but ‘t’ has a Bad data exception, “must have a known encoding”. I have tried various re-encoding attempts but so far I have failed.

Please can someone point me in the right direction?

The documentation says “You can also convert a String with a known encoding to a Text using the String.ToText method:”

It does not mention how exactly you define the encoding, so try using DefineEncoding; but as with all new framework questions I would point you toward the old framework until the new framework is a little more mature and usable.

Thanks Tim,
DefineEncoding did the trick, must have been amongst the many things I didn’t try.

[code] Dim s As String = URLParameter(“TestParameter”)
System.DebugLog(s)

Dim reEncoded as String
reEncoded=DefineEncoding(s, Encodings.UTF8)

Dim t As text
t = reEncoded.ToText
System.DebugLog(t)[/code]

It works now :slight_smile: