开发者

Difference Between Single and Double Quoted Strings in ActionScript

开发者 https://www.devze.com 2022-12-16 07:40 出处:网络
Is there any difference between single and double quoted strings in ActionScr开发者_开发百科ipt?You can use either as delimiter for a string. They are however not interchangeable, i.e. you can\'t star

Is there any difference between single and double quoted strings in ActionScr开发者_开发百科ipt?


You can use either as delimiter for a string. They are however not interchangeable, i.e. you can't start a string with an apostrophe and end it with a quotation mark.

The only difference is which characters you need to escape. Inside a string delimited by quotation marks you need to escape quotation marks but not apostrophes, and vice versa.

To put the text He said "It's all right" and laughed. in a string you can use:

"He said \"It's all right\" and laughed."

or:

'He said "It\'s all right" and laughed.'


No.

// * required - at least 15 characters


There is no difference.

This is from 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
    "moock@moock.org"   // A self-promotional string
    "123"               // It may look like a number, but it's a string
    'singles'           // Single quotes are acceptable too


No, apart from it being easier to include single quotes in double quoted strings and vice versa.


In Actionscript itself, there are not differences, other than the availability of the unused delimiter without escape characters.

In Flash Builder, a common AS3 authoring IDE for Flex, autocomplete for compatible event types (e.g., Event.COMPLETE) on addEventListener will not work if those event types are defined with single quotes rather that double quotes.

Suppose you have a class a tag it as dispatching a particular event type with the Flex meta tag.

[Event(name="foo",type="pkg.events.Constants")]
class SomethingThatDispatchesFoo extends EventDispatcher {

If your event constant class is structured like this:

class Constants {
  public static const FOO:String = 'foo';
}

Then autocomplete will give you 'foo'. However, if it's structured like this:

class Constants {
  public static const FOO:String = "foo";
}

The autocomplete will give you Constants.FOO.

0

精彩评论

暂无评论...
验证码 换一张
取 消