How do I insert an '&' character in a button caption

All said in the title…

Just Type it twice, like && :wink:

Thanks!!

Do you understand why that is though?

Taken from http://developer.xojo.com/literals

[quote]Ampersand (&)
The ampersand character (&) is often interpreted as a keyboard shortcut when used for user interface labels, such as for buttons, menus, label controls. If you want to display an & in these situation, simply use two of them together, such as “&&”.[/quote]

Taken from http://developer.xojo.com/userguide/desktop-menus

[quote]Accelerator Keys
Windows and Linux also have the concept of keyboard accelerators. In addition to the keyboard equivalent, which work on all platforms, you can also add a keyboard accelerator for each menu and menu item. When you designate a key as the keyboard accelerator, it is underlined in the menu name or menu item. The user can display the menu or invoke the menu item by holding down Alt and pressing the accelerator key. With a comprehensive system of accelerators, a user can use the menu system without using the mouse at all.
To designate the accelerator key, precede the letter by an ampersand ("&") in the menu or MenuItem Text property. For example, if you are creating a menu named “Actions” and you want to make the keyboard accelerator the “A”, you would enter “&Actions” in the Text property. To make the “t” the accelerator key, enter “Ac&tions”.
To display an ampersand in the menu, you need to double it like this: “&&”.
Accelerators do not work on Mac and are not displayed, but you still need to use a double-ampersand “&&” to display a single ampersand in a menu.[/quote]

I fix this by doubling the & just before writing the string to the label/menu/popup.

E.g.:

itemPtr.Text = name.ReplaceAll ("&", "&&") groupsPopup.AddRow (rega.Field("nickname").StringValue.ReplaceAll ("&", "&&"))

Now, can someone confirm that in all cases what I subsequently read back from the label/menu/popup will give me just the single ampersand? That seems to be the case but it would be nice to know for certain. The documentation doesn’t appear to mention this point.

It happens in all areas where the ampersand is used in an UI Label. Not in TextAreas, TextFields, Label.Text Properties, …

What happens in all those areas?

A single ampersand will not show, but two will show as a single one? :slight_smile:

Errm yeah, I know that, thanks. Its not what I’m asking. I’m asking whether, on reading the string back from the control, I get back the same string that I started with before I doubled up the ampersands.

Why not just try? :slight_smile:

Because for something like this, it makes more sense to ask.

but had you tried it you would have known the answer 4 hours sooner :slight_smile:

I have tried it. Well before I posted upthread, in fact,and I rely on it and have for some years. But as I’ve had no response yet from anyone in the know that this is how it’s supposed to work, and AISB the docs don’t cover the point, I don’t yet know for a fact that I can rely on it.

a Double && is only translated within the context stated above… if it appears in a normal “string” it is returned AS-IS

And as to “supposed” to… regardless of what anything is “supposed” to do, what it DOES do is what is important, and that is observable.

and as for “relying” on it… anything is subject to change… not that it should, just that it could