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

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?"
主站蜘蛛池模板: 长乐市| 镇安县| 宣恩县| 西宁市| 木兰县| 马龙县| 延寿县| 湖北省| 黔西| 新乡市| 堆龙德庆县| 丘北县| 永安市| 桃源县| 青龙| 宁海县| 安丘市| 蓝田县| 日土县| 永春县| 东丽区| 翁牛特旗| 安陆市| 淮阳县| 沐川县| 普格县| 桂平市| 南召县| 建始县| 麻城市| 林甸县| 鸡西市| 马公市| 盐源县| 得荣县| 福泉市| 临沂市| 溧阳市| 陵水| 稻城县| 友谊县|