Lua雜項運算子範例

2019-10-16 23:12:46

Lua語言支援的其他運算子包括連線和長度。

編號 描述 範例
.. 連線兩個字串 如果aHellobWorlda..b將返回Hello World
# 返回字串或表長度的一元運算子。 #"Hello" 將返回 5

範例

請嘗試以下範例以了解Lua程式設計語言中可用的其他運算子 -

a = "Hello "
b = "World"

print("Concatenation of string a with b is ", a..b )

print("Length of b is ",#b )

print("Length of b is ",#"Test" )

當構建並執行上述程式時,它會產生以下結果 -

Concatenation of string a with b is     Hello World
Length of b is     5
Length of b is     4