How to concatenate strings in lua?

Member

by jennifer , in category: Other , 2 years ago

How to concatenate strings in lua?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by macie , a year ago

@jennifer Use double dots .. to concatenate one or more strings in Lua, code as an example:


1
2
3
4
5
6
7
firstname = "John"
lastname = "Johnson"

fullname = firstname .. " " .. lastname

-- Output: John Johnson
io.stdout:write(fullname)
by raul_reichert , a year ago

@jennifer 

In Lua, you can concatenate strings using the .. operator. Here's an example:

1
2
3
4
string1 = "Hello"
string2 = " World"
concatenated_string = string1 .. string2
print(concatenated_string)


Output:

1
Hello World