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

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?"
主站蜘蛛池模板: 罗源县| 老河口市| 东台市| 汉川市| 中卫市| 静安区| 景德镇市| 靖州| 马边| 岱山县| 丰县| 瑞安市| 南川市| 周至县| 禹城市| 商都县| 太谷县| 儋州市| 大同县| 安顺市| 抚州市| 波密县| 防城港市| 靖边县| 洛宁县| 和田县| 武乡县| 宁武县| 翁源县| 岳普湖县| 东阿县| 神农架林区| 开化县| 宁津县| 库伦旗| 子长县| 江川县| 澄城县| 崇义县| 从化市| 和政县|