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

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?"
主站蜘蛛池模板: 凤山县| 上虞市| 龙井市| 玉溪市| 漠河县| 宁波市| 通辽市| 龙游县| 镇江市| 香港| 嘉禾县| 大渡口区| 太康县| 嵊州市| 兴海县| 宁阳县| 利辛县| 济阳县| 砚山县| 吉林省| 吴堡县| 夏河县| 上犹县| 舞钢市| 巩留县| 甘南县| 淄博市| 小金县| 台东市| 绵竹市| 巧家县| 新巴尔虎左旗| 剑阁县| 安阳市| 长宁县| 西昌市| 论坛| 隆尧县| 陕西省| 汾西县| 新巴尔虎左旗|