官术网_书友最值得收藏!

Strings

Earlier in this chapter, you saw some code examples using sequences of characters. Those sequences of characters are called strings. Strings may consist of any character, including numeric values.

Quoting strings

There are three ways to quote strings: with double quotes, with single quotes, and with square brackets.

Note

When quoting strings, make sure that only straight quotes are used in your code and not curly quotes; or else, it will not compile.

Double quote characters " mark the beginning and end of the string. Here is an example:

print("This is my string.")  -- This is my string.

You can also quote strings using the single quote character '. Single quotes work the same as double quotes, except that single-quoted strings can contain a double quote. Here is an example:

print('This is another string.')  -- This is another string.

print('She said, "Hello!" ')  -- She said, "Hello!"

Finally, using a pair of square brackets will also quote strings. They are used mainly for strings when double or single quotes cannot be used. There are not many cases where this occurs, but they will do the job:

print([[Is it 'this' or "that?"]]) -- Is it 'this' or "that?"
主站蜘蛛池模板: 元谋县| 顺平县| 克拉玛依市| 赤峰市| 贵溪市| 锡林浩特市| 奉贤区| 淮安市| 晋江市| 霍州市| 深州市| 且末县| 石泉县| 新津县| 交口县| 仁怀市| 太和县| 高平市| 鄄城县| 抚远县| 咸阳市| 广丰县| 平谷区| 田阳县| 金坛市| 达州市| 家居| 邻水| 淳化县| 耒阳市| 香格里拉县| 汝州市| 宝清县| 广元市| 江口县| 威远县| 博罗县| 吐鲁番市| 海兴县| 东宁县| 翼城县|