当前位置 : 主页 > 网络编程 > lua >

如何打破一个大的lua字符串成小的

来源:互联网 收集:自由互联 发布时间:2021-06-23
我有一个大字符串(一个base64编码的图像),它是1050个字符长。如何在C中附加一个由小的字符串构成的大字符串 function GetIcon() return "Bigggg string 1"\"continuation of string"\"continuation of string"\
我有一个大字符串(一个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"
上一篇:lua ffi.string
下一篇:嵌入Lua在C
网友评论