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

Strings

Earlier in this chapter, you saw some code examples using sequences of characters. Those sequences of characters are called strings. Strings may contain characters with any numeric value, including embedded zeros. This also means that binary data can be stored in a string.

Quoting strings

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

Tip

When quoting strings, make sure that only straight up and down quotation characters are used in your code or else it will not compile.

Using double quote characters " mark the beginning and end of the string. For example:

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

You can also quote strings by using the single quote character '. Single quotes work the same as double quotes except that single-quoted strings can contain a double quote.

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

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

Lastly, using a pairs 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 that this occurs, but they will do the job.

print([[Is it 'this' or "that?"]]) -- Is it 'this' or "that?"
主站蜘蛛池模板: 山西省| 巨野县| 巴林右旗| 长海县| 苏尼特左旗| 秭归县| 乐平市| 宾阳县| 安庆市| 金山区| 鄂托克前旗| 三河市| 新丰县| 邵武市| 微山县| 怀宁县| 错那县| 乐平市| 红原县| 南投市| 漳平市| 石门县| 海原县| 东海县| 乐昌市| 那坡县| 绥棱县| 富顺县| 同心县| 瑞昌市| 登封市| 文登市| 新郑市| 舞钢市| 禄丰县| 东乡族自治县| 南宫市| 监利县| 竹溪县| 望江县| 灵石县|