String Literal tilde ~

Monkey Forums/Monkey Bug Reports/String Literal tilde ~

therevills(Posted 2012) [#1]
Should this compile/work?

Function Main()
    Print "~"
End



Xaron(Posted 2012) [#2]
I guess not.

~ looks like an escape character so you can do stuff like ~n for a line feed.

To print ~ you should do IMO

Print "~~"


Haven't tested it though... ;)


ziggy(Posted 2012) [#3]
I think is should work as it is not scaping anything BUT the easiest way to find out is testing it yourself.


therevills(Posted 2012) [#4]
@Ziggy - yep I have tested it and it does compile in Monkey, but I think it shouldnt (also in BlitzMax you get an error trying this).

The Monkey docs states:
String literals are sequences of characters enclosed in "" (quotation marks). String literals may also include escape sequences - special sequences of characters used to represent unprintable characters.

You can use the following escape sequences in string literals:

Escape sequence Character code
~q 34 (quotate mark ")
~n 10 (newline)
~r 13 (return)
~t 9 (tab)
~z 0 (null>
~~ 126 (tilde ~)




Floyd(Posted 2012) [#5]
It looks wrong, or at least peculiar. Monkey considers the strings "~" and "~~" to be equal.


ziggy(Posted 2012) [#6]
That's what I would expected. I would only scape a ~ if I want to write this text: ~q or this text: ~n or anything that requires me to scape the ~ char. If I do not need to scape it, why should I be forced to?