LCB: Error: illegal escape in string
Peter TB Brett
peter.brett at livecode.com
Wed Feb 24 16:41:35 CET 2016
On 24/02/2016 12:26, Stephen MacLean wrote:
>> Hi Stephen,
>> In LiveCode Builder, quoted strings treat the '\' character as an escape character. It's explained in the LiveCode Builder Language Reference guide.
>> So, you need to replace your '\' with '\\', and everything should work nicely for you.
> Thanks for that, I will give it a try!
> Can you explain why it’s treated that way inside a quoted string? Just curious:)
While we were designing LiveCode Builder, we wanted to make it easier to
create string literals with *any* character in them, including the quote
character, control characters, and non-native characters.
This requires the use of some sort of "escape character" to indicate the
start of special sequences. We could have come up with our own,
LiveCode-specific one, but most programming languages use "\" so that's
what we went with. There didn't seem to be much to gain by being
different for the sake of being different.
This does make writing complex string literals quite a bit easier. For
example, in LiveCode builder you can write:
put "\"Come to the pub for a beer,\" she said.\n" into tVar
rather than the LiveCode Script equivalent:
put quote & "Come to the pub for a beer," & quote && "she said." &
return into tVar
> Also, can you point me to the LCB Language Reference guide? Or is that what’s in the dictionary? I’d love to be able to dive into an actual reference!
1. Open the 8.0.0-dp-15 IDE
2. Open the dictionary
3. Switch to the "Guides" tab
4. Select "LiveCode Builder Language Reference" from the menu.
There's also a "LiveCode Builder" API reference in the dictionary.
Dr Peter Brett <peter.brett at livecode.com>
LiveCode Open Source Team
LiveCode 2016 Conference: https://livecode.com/edinburgh-2016/
More information about the use-livecode