US-ASCII Encoding?

I’ve got a problem I can’t quite figure out. I’m thinking it’s an Encoding issue, but I’m often barking up the wrong tree, so maybe some has a suggestion?

The issue is that for some reason, when I pull a string from a MemoryBlock and then show it in a TextField or TextArea, the EndOfLines become a non-printable character instead of an end-of-line.

The weird thing is that if I look at the encoding of the string I’m sending, I get this problem if the Encoding is Nil. A string created a different way (from individual characters), shows an encoding of “US-ASCII”, which is not one of the defined encodings that I can find, but then the EndOfLine works properly.

Converting the Encoding of the strings that have Nil Encoding doesn’t seem to fix the problem either.

The strings both display properly, but the EndofLine (which is not part of the string) doesn’t.

ConvertEncoding doesn’t seem to be working either, but I’m probably using it wrong. I’ve been working on this for a while and getting nowhere! Argh.

How do I add an attachment?

I guess until I figure out how to attach, here’s a link to a sample project.

TestEncoding Project

MemoryBlock.StringValue doesn’t set an encoding on the resulting string. You have to do it using DefineEncoding. ConvertEncoding is only for strings that already have an encoding.

So, your line should be something like this:

Dim s As String = m.StringValue(Start + 1, Length).DefineEncoding(Encodings.UTF8)

I used UTF8 because that’s the default encoding Xojo uses (except in cases like MemoryBlock.StringValue :grinning:).

1 Like

Thank you, Jay.

Ok, so that answers the question about how to change Encodings, but I still don’t understand why, when a non-encoded string is sent to a TextArea, the EndOfLine doesn’t work. What’s the connection there?

Also, what is US-ASCII Encoding? I assume it’s just “ascii” but why is it reported as an encoding that’s not in the list, or are there other encodings that are not on the Encodings list in Xojo?

I think all of the Xojo controls expect an encoded string (try it with a multi-line label). I guess you could call it a bug, but they’ll probably just say, “strings assigned to controls must have a non-nil encoding.”

As to the US-ASCII vs ASCII, I assume that’s just an oversight in the documentation. Should probably be reported for correction.

Edit to add: “US-ASCII” is redundant though, since the “A” in “ASCII” is for “American”. :wink:

2 Likes

Thanks again, Jay.
It seems odd to me that the non-encoded string itself displays correctly, indicating that the control seems to be ok with it, but that the EndOfLine is where it chokes. Does Xojo somehow automagically encode any EndOfLines with the encoding of the string they’re concatted with? And if so, why are the characters ok, but the EndOfLine not?

As far as I know, US-ASCII = ASCII.

As for the odd EndOfLine issue, it wouldn’t surprise me if it’s just something to do with how the Xojo framework internally handles strings that isn’t coping with a Nil encoding.