Linux 拨号vps windows公众号手机端

Lua中怎么连接和格式化字符串

lewis 7年前 (2018-03-16) 阅读数 8 #程序编程
文章标签 Lua

要连接和格式化字符串,在Lua中可以使用字符串连接运算符..string.format()函数。

  1. 字符串连接:
local str1 = "Hello"
local str2 = "World"
local result = str1 .. " " .. str2
print(result)  -- 输出:Hello World
  1. 字符串格式化:
local name = "Alice"
local age = 25
local result = string.format("My name is %s and I am %d years old.", name, age)
print(result)  -- 输出:My name is Alice and I am 25 years old.

string.format()中,%s表示字符串类型,%d表示整数类型,可以根据需要使用不同的格式化标识符。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门