Clipboard.SetText not working

I have a debugging tool which logs data from a serial port. The data is a mixture of text descriptions and actual data bytes. The data bytes are not text, often can’t be displayed as text. Xojo can however store those bytes in a string, which is what I do. I have a string array myDebugLog() which contains all the messages. The problem comes when I want to copy this to the clipboard. I use the following code:

dim L as string = DefineEncoding( join( myDebugLog(), EndOfLine ), Encodings.UTF8 )
dim c as new Clipboard
c.SetText( L )

It doesn’t work. I’m sure the data goes to the clipboard, but apparently because it contains non-text bytes, when I go to paste it into a text editor, there’s nothing there. I know I can use a clipboard utility or look at the data in the IDE, but this is for users of my software to be able to send me their debug logs if they need to. Any ideas how to get this to work? I also tried:

c.AddRawData( L, "public.utf8-plain-text" )

Same result.

If you’re on macOS, Apple provides an additional tool with Xcode called Clipboard Inspector which may give you some insight.

You could also use EncodeHex or EncodeBase64 on the data to make it transferable.

Ideally I’d like a way to use EncodeHex on only the bytes that are non-printable. I think I can write a method which does that, but asking just in case, is there already something for that available?

You might try EncodeUrlComponent. Otherwise decoding will be a pain because you would need to have a way to know where they all are to decode them.

Good idea! Saved me some work. Along with some replacement for spaces and EOL, that works very well.