Cast string to UInt8()

Is there a way (or alternative) to get the compiler to treat a String as a UInt8() array? What I’m trying to do is this:

clipboard.rawdata -> string
string -> uint8()
uint8() assigned to (core) dictionary entry
dictionary converted to JSON

I’m looking to get data on the clipboard into a JSON byte array to send to an external API. I know the string->uint8() conversion can be done with a copy loop, but would be more efficient if I could just treat it as a byte array. Looked at options to go through memoryblocks, but couldn’t find any path.

[quote=357355:@Matthew Dinmore]Is there a way (or alternative) to get the compiler to treat a String as a UInt8() array?
[/quote]
No strings are not uint8’s
You might want to look up “val”

This is the closest I can get:

dim mb as MemoryBlock = s
dim p as ptr = mb
dim lastIndex as integer = mb.Size - 1
dim bytes() as byte
for i as integer = 0 to lastIndex
  bytes.Append p.Byte( i )
next

dim json as text = Xojo.Data.GenerateJSON( bytes )

That generates an array, not an object, so modify as needed.

Yes, I can do the loop – that’s what I’m trying to avoid for performance. And, yes, I know uint8 <> string and what val does. Just wondered if there was a way to treat the bucket-of-bytes that is a string (which can be directly converted in place to a memoryblock) to a byte array as recognized by the compiler for the purpose of leveraging the builtin dictionary conversion to a JSON array. Guessing this means there’s no shortcut around a copy.