Lua 額外提供兩個實用運算子:.. 字串連接、# 取得長度(字串為字元數、表為陣列部分長度)。
| 運算子 | 功能 | 範例 | 結果 |
|---|---|---|---|
.. | 字串連接 | "Hello " .. "World" | "Hello World" |
# | 長度 | #"Test" | 4 |
a = "Hello "
b = "World"
print("Concatenation:", a .. b) --> Hello World
print("Length of b:", #b) --> 5
print("Length of 'Test':", #"Test") --> 4
.. 兩側必須為字串或可轉字串(數值會自動轉換),否則報錯。# 僅計算陣列部分(從 1 開始連續整數鍵),雜湊部分不計入。table.concat 避免效能問題。