Lua雜項運算符示例

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

上一篇: Lua運算符 下一篇: Lua迴圈