I just noticed something with an app I make some time ago. I’m using a binaryStream to save text like “Mac & Cheese” . I have a listbox that displays that as it should. When I populate a popupMenu with that same file I get “Mac Cheese”. Where did “&” go? I know it’s there, I see it in the listbox. Hope my explanation is clear. Below is a bit of code. Thanks for any help or suggestions. (FYI I don’t really know what I’m doing, but sometimes things do work)
If f.exists then
b=BinaryStream.Open(f.child("Location"), false)
u=b.ReadInt8
for i=1 to u
me.addrow b.readPString
next
b.close
end if
the & is the accelerator character marker - its particularly relevant for Windows
double it up
If f.exists then
b=BinaryStream.Open(f.child("Location"), false)
u=b.ReadInt8
for i=1 to u
me.addrow replaceall(b.readPString, "&", "&&")
next
b.close
end if
FYI - there are other potential issues lurking in that code
Strings have the notion of an Encoding and when you read from disk it is not set
If you try to put something like an û in one of your strings I suspect you would not get the right value back
Thanks to this great forum for all the help with my dinky little problems. So, I’ve been reading and playing around with encoding-something I never even thought about. Pretty interesting. Seems to be working now but is this really correct? I’ve been experimenting with all kinds of strange characters and they all show correctly. Now, if I don’t use “&”, “&&” in addition to DefineEncoding(Encodings.UTF8) (As seen below) I still won’t get “Mom & Dad” just “Mom Dad”. So, is something still not right or is this how it’s supposed to work? “&”, “&&” always necessary? Thanks.
If f.exists then
b=BinaryStream.Open(f.child("Location"), false)
u=b.readint8
for i=1 to u
Window1.PU_Location.addrow replaceall(b.readPString, "&", "&&").DefineEncoding(Encodings.UTF8)
next
b.close
end if
end if
To show the single & in something in your ui it’s almost always required (the only exception I can think of would be text in a text field or text area - there could be others)
READING data from ANYTHING (file, serial port, database, etc) should ALWAYS use define encoding.
Unless the data is entered into your application via a text field, text area, etc (some UI element) then you probably need to define the encoding.