Corona SDK Mobile Game Development:Beginner's Guide
上QQ阅读APP看书,第一时间看更新

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?"