This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Banzai_Bill's profile picture

Is that possible?

Started by Banzai_Bill, 08 January 2013 - 11:00 PM
Banzai_Bill #1
Posted 09 January 2013 - 12:00 AM
Is it possible to write a "\" in ComputerCraft?
Evertime I get a unfinished String error…
theoriginalbit #2
Posted 09 January 2013 - 12:01 AM
In programming languages \ is a terminating character. meaning that \n actually means new line, or \t means tab. this means that if we want strings for example with a " ' or \ we need to place a \ in front of it… so \ is actually \\ in a string… hope this helps :)/>
Orwell #3
Posted 09 January 2013 - 12:03 AM
You need to escape it, this means prepending it with another '\'. Example:

print("\\backslash")
You can do the same for quotes and other special characters. Quotes could be printed like:

print(" \"double quotes\" ")

Edit: heavily ninja'd. On a side note, you can also use [[ ]] to surround your strings, this ignores every special character. E.g.:

print( [[I can put "quotes" and \backslashes here
and even newlines if I want to!]] )
Banzai_Bill #4
Posted 09 January 2013 - 12:04 AM
Yes that worked thanks :D/>