ActionScript中单引号和双引号字符串的区别
答
您可以使用作为分隔符的字符串。但它们不可互换,即不能用撇号开始字符串,并用引号结束。
唯一的区别是你需要转义哪些字符。在由引号分隔的字符串中,您需要转义引号而不是撇号,反之亦然。
把文本He said "It's all right" and laughed.
在一个字符串,你可以使用:
"He said \"It's all right\" and laughed."
或:
'He said "It\'s all right" and laughed.'
答
不,除了双引号字符串更容易包含单引号,反之亦然。
答
号// *为必填 - 至少15个字符
答
没有区别。
也就是说从ActionScript: The definitive Guide
String is the datatype used for textual data (letters, punctuation marks, and other characters). A string literal is any combination of characters enclosed in quotation marks:
"asdfksldfsdfeoif" // A frustrated string
"greetings" // A friendly string
"[email protected]" // A self-promotional string
"123" // It may look like a number, but it's a string
'singles' // Single quotes are acceptable too
答
在ActionScript本身,不会有差别,比未使用的分隔符的不可用性等转义字符。上addEventListener
will not work
在Flash Builder,公共AS3创作IDE针对Flex,自动完成兼容事件类型(例如,Event.COMPLETE
)如果这些事件类型是通过单引号而是双引号所定义。
假设您有一个类标记为使用Flex元标记调度特定的事件类型。
[Event(name="foo",type="pkg.events.Constants")]
class SomethingThatDispatchesFoo extends EventDispatcher {
如果你的事件不断类的结构是这样的:
class Constants {
public static const FOO:String = 'foo';
}
然后自动完成会给你'foo'
。但是,如果它的结构是这样的:
class Constants {
public static const FOO:String = "foo";
}
自动完成会给你Constants.FOO
。
这是我第一次看到编译器永远不会看的东西的评论。 ^^ – LoremIpsum 2011-12-18 09:02:42