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

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?"
主站蜘蛛池模板: 安吉县| 肃宁县| 洞头县| 若尔盖县| 日土县| 衡阳市| 高淳县| 正蓝旗| 高台县| 彭阳县| 茶陵县| 大洼县| 江达县| 文登市| 杭锦旗| 广水市| 黑河市| 芦山县| 大兴区| 小金县| 康平县| 万宁市| 牡丹江市| 六枝特区| 东乌| 连平县| 固原市| 和静县| 宝丰县| 洪江市| 曲阳县| 兰考县| 乐陵市| 垫江县| 元谋县| 云龙县| 兴文县| 随州市| 凤城市| 仁布县| 乌拉特中旗|