Skip to content

backslash breaks strings #1235

Answered by Lupus590
C4PTRAMPAGE asked this question in Q&A
Discussion options

You must be logged in to vote

Backslash is the escape character, which means that it has a special meaning in strings, its exact behaviour is decided by the character following it..

You want a literal backslash in your string, so to do that you need to escape the backslash, this is done by placing two backslashes every time you want one to be in the string.

print("\\") --> "\"

The reasons that your string is breaking there is that \" tells lua to put the " character in the string and not to close that string. So things break when lua gets to the end of the line thinking that you wanted to escape the closing quote and thus not finding a quote mark that closes the string before the end of the line. So it ends up with a …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by C4PTRAMPAGE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants