gpt4 book ai didi

string - 如何将大的 lua 字符串分成小字符串

转载 作者:行者123 更新时间:2023-12-02 14:58:03 24 4
gpt4 key购买 nike

我有一个大字符串(base64 编码的图像),它有 1050 个字符长。如何附加由小字符串组成的大字符串,就像 C 中的这样

 function GetIcon()
return "Bigggg string 1"\
"continuation of string"\
"continuation of string"\
"End of string"

最佳答案

根据Programming in Lua 2.4 Strings :

We can delimit literal strings also by matching double square brackets [[...]]. Literals in this bracketed form may run for several lines, may nest, and do not interpret escape sequences. Moreover, this form ignores the first character of the string when this character is a newline. This form is especially convenient for writing strings that contain program pieces; for instance,

page = [[
<HTML>
<HEAD>
<TITLE>An HTML Page</TITLE>
</HEAD>
<BODY>
<A HREF="http://www.lua.org">Lua</A>
[[a text between double brackets]]
</BODY>
</HTML>
]]

这是与您要求的最接近的事情,但是使用上述方法会将换行符嵌入到字符串中,因此这不会直接起作用。

您还可以通过字符串连接来完成此操作(使用 ..):

value = "long text that" ..
" I want to carry over" ..
"onto multiple lines"

关于string - 如何将大的 lua 字符串分成小字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6795213/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com