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

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?"
主站蜘蛛池模板: 井研县| 砚山县| 磐石市| 惠州市| 开阳县| 嘉祥县| 当涂县| 车险| 陇南市| 右玉县| 盈江县| 北流市| 湖口县| 巴彦淖尔市| 扎鲁特旗| 安康市| 芒康县| 平远县| 清河县| 九江县| 新乡市| 碌曲县| 汶上县| 石渠县| 饶河县| 广德县| 新野县| 水富县| 定日县| 青神县| 广宗县| 福鼎市| 临安市| 宁德市| 邯郸市| 乌兰县| 天全县| 宁南县| 金华市| 武宣县| 兴山县|