如何将多个变量拼接成一段完整的文字字符串?

2026-04-01 19:211阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计299个文字,预计阅读时间需要2分钟。

如何将多个变量拼接成一段完整的文字字符串?

我尝试将变量连接成纯文字字符串,纯文本是为了提高可读性。例如,`myString=test`,`myString2=[first part of the string, this is a \ + myString + \ string, last part of the string]`,然后输出`myString2`。但这实际上输出的是字符串“first part of the string this is a test string last part of the string。

我试图将变量连接成一个纯文字字符串,纯粹是出于可读性目的,例如

myString = "test" myString2 = [[ first part of the string this is a " .. myString .. " string last part of the string]] print(myString2)

但这确实是输出

first part of the string this is a " .. myString .. " string last part of the string

我确信它很简单,但我已经尝试使用谷歌搜索来了解如何实现这一目标并且空白.

如何将多个变量拼接成一段完整的文字字符串?

双括号分隔符内的引号没有做任何事情.结束双支架的唯一方法是使用双支架:

myString2 = [[ first part of the string this is a ]] .. myString .. [[ string last part of the string]]

那会给你:

first part of the string this is a test string last part of the string

见:www.lua.org/pil/2.4.html

本文共计299个文字,预计阅读时间需要2分钟。

如何将多个变量拼接成一段完整的文字字符串?

我尝试将变量连接成纯文字字符串,纯文本是为了提高可读性。例如,`myString=test`,`myString2=[first part of the string, this is a \ + myString + \ string, last part of the string]`,然后输出`myString2`。但这实际上输出的是字符串“first part of the string this is a test string last part of the string。

我试图将变量连接成一个纯文字字符串,纯粹是出于可读性目的,例如

myString = "test" myString2 = [[ first part of the string this is a " .. myString .. " string last part of the string]] print(myString2)

但这确实是输出

first part of the string this is a " .. myString .. " string last part of the string

我确信它很简单,但我已经尝试使用谷歌搜索来了解如何实现这一目标并且空白.

如何将多个变量拼接成一段完整的文字字符串?

双括号分隔符内的引号没有做任何事情.结束双支架的唯一方法是使用双支架:

myString2 = [[ first part of the string this is a ]] .. myString .. [[ string last part of the string]]

那会给你:

first part of the string this is a test string last part of the string

见:www.lua.org/pil/2.4.html