简体   繁体   English

Actionscript 3中的多行字符串文字

[英]Multiple Line String Literal in Actionscript 3

How do you specify a multiple line string literal in Actionscript 3? 如何在Actionscript 3中指定多行字符串文字?

Note that this is sometimes called a here document , heredoc, hereis, multiline string, etc. 请注意,这有时称为here文档 ,heredoc,hereis,multiline string等。

There is one example from this site: Multi-line strings in Actionscript 3 这个站点有一个例子: Actionscript 3中的多行字符串

Because actionscript is based on javascript, you can use the cdata tags. 因为actionscript基于javascript,所以您可以使用cdata标签。

private var myString:String = ( <![CDATA[

Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Maecenas dui lacus, sollicitudin nec laoreet a, vestibulum a 
odio. Sed et lorem mauris, non porttitor ligula. Aliquam 
convallis dolor rutrum justo semper nec aliquet orci....

]]> ).toString();

wow, very clever ... actually, i think this won't even work in most browser when it comes to JavaScript ... 哇,非常聪明......实际上,我认为这在大多数浏览器中都不适用于JavaScript ......

i just wanted to amend an explanation of what actually happens: AS3 allows inline xml declarations through xml literals (which should be part of E4X) ... what you do, is declare an XML literal and then convert it to a String ... likewise, you could write: 我只想修改实际发生的解释:AS3允许通过xml文字(应该是E4X的一部分)的内联xml声明...你做的是,声明一个XML文字,然后将其转换为String ...同样,你可以这样写:

private var myString:String = ( [
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"Maecenas dui lacus, sollicitudin nec laoreet a, vestibulum a",
"odio. Sed et lorem mauris, non porttitor ligula. Aliquam",
"convallis dolor rutrum justo semper nec aliquet orci....",
] ).join("\n");

that would be declaring an Array literal and converting it to a String ... 这将声明一个Array文字并将其转换为String ...

so in the end, you instruct the flash player to create an XML object with one text node containing your text, and then use the String representation of that object ... 所以最后,你指示flash播放器创建一个XML对象,其中一个文本节点包含你的文本,然后使用该对象的String表示...

( little side note : it is bad practice to declare String content in your code ... this should be loaded externally at runtime) 小方注意 :在代码中声明String内容是不好的做法......这应该在运行时从外部加载)

greetz 格尔茨

back2dos back2dos

这对我很有用:

private var myString:String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."+"\n"+ "Maecenas dui lacus, sollicitudin nec laoreet a, vestibulum a";

you can also do this 你也可以这样做

var quote:String = "This was my very first experience with a video game. \
        Despite only being 4 or 5 years old when I first saw this game, \
        the comedic characters and unforgettable soundtrack still brings me incredible joy."

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM