backslash escaped in Option menu

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

backslash escaped in Option menu

Post by kaveh1000 »

Please see attached sample stack.

It seems the backslash is used as an escape character, not a literal "\" in option menu content. Here is what the menu content entry is and what is seen in the menu choice:

Code: Select all

\text  > "text"
\ text > " text"
\\text > "\text"
Is this expected behaviour? I hope not!
Attachments
backslash in menu.zip
(736 Bytes) Downloaded 298 times
Kaveh
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: backslash escaped in Option menu

Post by Klaus »

Hi kaveh1000,

yes this is exspected and correct behavior!

\text -> Nothing to escape so we see -> "text"
\ text -> The SPACE is escaped although not neccessary -> " text"
test -> same as above without the backslash -> " test"***
\\text -> the second Backslash is escaped and we see only one backslash in the menu -> "\text"

***HTML will remove the space at the beginning of the line unfortunately.

What do you want to achieve?


Best

Klaus
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: backslash escaped in Option menu

Post by bogs »

What Klaus said. The only thing I could add is that this is *not* just related to the '\' character in the menu, but a few others as well, such as '&' (ampersand).

When you need to see one of these types of characters in the menu, you need to 'double it up' as Klaus points out, so if you wanted to see an &Menuitem in the menu, like for instance, a menuItem [Close & Save], you'd have to have it written like [Close && Save].

That should make it clear as mud :P
Close and save...
Close and save...
Image
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: backslash escaped in Option menu

Post by kaveh1000 »

Thank you both. So what is the exact rule for rendering the content? Klaus mentioned HTML, but it is not setting the content as HTMLtext. When I put <b>text</b> I see the same text rendered. And why not just put the text verbatim without escaping?

Sorry if it is elementary questions. I can achieve what I want by escaping the chars, but just want to check the rule...
Kaveh
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: backslash escaped in Option menu

Post by Klaus »

I meant that this HTML Page ate the SPACE at the beginning of this line:
...
test -> same as above without the backslash -> " test"
...

Some basics:
https://en.wikipedia.org/wiki/Escape_character
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: backslash escaped in Option menu

Post by kaveh1000 »

Thank you so much all. I have an application where I need to auto-populate menus with text that has weird characters, including "\". So I will just have a function that converts these before populating the menu text.
Kaveh
Post Reply