簡單介紹 字串指的就是一段文字 通常是用雙引號來表示print(44) -- 印出數字 "44" print("hello") -- 印出字串 "hello" -- Lua 裡可以用一個變數來儲存一段文字 local msg = "hello" print(msg) -- 一樣印出字串 "hello"計算字數 使用"#"符號就行了local msg="hello" print(#msg) -- 印出數字 "5"字串的寫法 Lua 的字串有下面幾種寫法local str="It is a string" local str='It is a string' local str=[[It is a string]] -- 這是raw string換行符號-- 直接用 print() 來輸出文字會有換行效果 print("image01") print("image02") print("image03") -- 想直接在字串裡完成換行可以用 \n 符號 print("image01\nimage02\nimage03") -- 使用 \n 符號來完成換行實在是有點難看 -- 使用下面寫法可以直接忠實的呈現文字換行 print([[ image01 image02 image03]]) -- 兩邊可以安插一樣數量的等號,數量不限 -- 所以字串裡面要寫什麼都沒問題 print([===[ image01 image02 image03]===])拼貼文字-- 將兩個字串黏一起只需要用".."符號就行了 print("hello " .. "world") -- 印出 "hello world" -- 遇到數字一樣幫你轉成文字 local str1="I have " local str2=" apples" local x=2 local str = "Message:" .. str1 .. x .. str2 print(str) -- 印出 "Message:I have 2 apples"