String constant with non-ascii characters

Hello,

I’ve been butting my head against this one for awhile:

I know I can create a string constant with:

const strname as string = "contents"

How would I go about getting non-ascii characters in like this (which doesn’t compile):

const strname as string = &uAA + &uED

I could probably get away with a static instead of a constant, but when I do:

const c1 = &uAA
const c2 = &uED
static strname as string = c1 + c2 + c1

This results in a string that, when viewed in the debugger as a binary, is:

C2AA C3AD C2AA

I’m guessing that AA and ED map to 2-byte unicode characters. Any way around this? Lowering the values to something under 7F results in a 3-byte string, which is what I need. &h literals can’t be assigned to a string, and I’d like to avoid creating a byte and converting it to something that the string can handle as this function needs to be fairly speedy due to data rates/data size pushing performance already.

So what gives? Am I just missing some syntax here? Or is this not possible with a string? I’d rather not move it all into a MemoryBlock if I can avoid it.

Any characters above code point 127 will be encoded as at least 2 bytes in UTF8, and UTF8 is the default. You are really trying to plug in bytes, so you can use ChrB if you want to avoid a MemoryBlock:

static strname as string = ChrB( &hAA ) + ChrB( &hED )

The encoding of the resulting string will be nil.

The compiler is just not fully handling constant expressions yet, i.e. it’s missing code to handle this. It’s been like this for years, and there’s no way around it. The best you can do is to write the text you need in a text editor, copy it, and paste it into a class/module constant. That allows you to include Tabs, CRs etc.

A read only computed property (you really can’t syntactically tell the difference between a const & a read only property or a getter method only anyways)
Implement the getter only

Computed Property Strname as string Get return &uAA + &uED End Get

EDIT - The ONLY place this will make any difference is if you try to use the #ConstantName syntax in a layout element

Ah, ChrB() + ChrB() into a static, that should do it for me without causing too much slowdown. Guess I missed that one… I’m finding that the help files are not very helpful sometimes unless you’re already pretty familiar with the libraries… oh well.

OK…this may be ancient history (4 years ago) but thank you forum! I’ve tried many interesting combinations. I run a Shell and get the results which…may contain a few unusual characters like Hex FF. When I try to display the result in a WebTextArea is hands me some nasty JSON exception about an illegal character. It’s been interesting trying to figure out how to replace (ReplaceB) this byte in the string. — but this old posting told me how to solve it – using ChrB( &hFF ) Many thanks forum members.