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

前端之家收集整理的这篇文章主要介绍了如何打破一个大的lua字符串成小的前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个大字符串(一个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相关文章