- Lua Quick Start Guide
- Gabor Szauer
- 210字
- 2021-08-05 10:30:38
Escape characters
Strings need to be within quotes, but what happens when you need to put quotes inside the string? Lua doesn't care if a string uses single or double quotes, so long as the symbol at the start and end of the string matches, so technically this code would be valid:
message = 'he said "bye" and left'
print (message)
However, this is not desirable. As a convention, only double quotes will be used to represent a string throughout this book. To include a double quote within a string, the character must be escaped. Escaping a character means the character will be treated as part of the string, rather than a Lua instruction. To escape a character, place a \ in front of it, like so:
message = "he said \"bye\" and left"
print (message)
There are actually several escape characters that can be used when working with strings. The most often used escape characters are:
- \n: Newline, moves the cursor down one line
- \t: Horizontal tab, tabs over on the current line
- \\: Backslash, you have to escape the escape symbol
- \": Double quote, needed to include a quote in a string
The full list of supported escape symbols for Lua can be found online at https://www.lua.org/pil/2.4.html.
- 從零構(gòu)建知識(shí)圖譜:技術(shù)、方法與案例
- Django+Vue.js商城項(xiàng)目實(shí)戰(zhàn)
- HTML5 移動(dòng)Web開發(fā)從入門到精通(微課精編版)
- SQL Server 2012數(shù)據(jù)庫(kù)管理與開發(fā)項(xiàng)目教程
- 名師講壇:Spring實(shí)戰(zhàn)開發(fā)(Redis+SpringDataJPA+SpringMVC+SpringSecurity)
- Python面向?qū)ο缶幊蹋簶?gòu)建游戲和GUI
- Nginx實(shí)戰(zhàn):基于Lua語(yǔ)言的配置、開發(fā)與架構(gòu)詳解
- 低代碼平臺(tái)開發(fā)實(shí)踐:基于React
- Cybersecurity Attacks:Red Team Strategies
- HTML5開發(fā)精要與實(shí)例詳解
- Machine Learning With Go
- Xamarin Cross-Platform Development Cookbook
- Mastering Machine Learning with R
- Raspberry Pi Robotic Projects
- Puppet Essentials