最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

actionscript 3 - escaping characters in as3 as javascript does - Stack Overflow

programmeradmin0浏览0评论

I am having trouble escaping special characters in as3.

trace( escape("who are ü?") );

returns who%20are%20%uFFFD%3F

or

trace( encodeURIComponent("who are ü?") );

returns who%20are%20%EF%BF%BD%3F

while in javascript this

alert( encodeURIComponent("who are ü?") );

returns who%20are%20%C3%BC%3F

and

alert( escape("who are ü?") );

returns who%20are%20%FC%3F

Any suggestions how to get as3 to return escaped special characters as javascript is? Why is as3 apparently choking?

(here is a good reference: .html )

I am having trouble escaping special characters in as3.

trace( escape("who are ü?") );

returns who%20are%20%uFFFD%3F

or

trace( encodeURIComponent("who are ü?") );

returns who%20are%20%EF%BF%BD%3F

while in javascript this

alert( encodeURIComponent("who are ü?") );

returns who%20are%20%C3%BC%3F

and

alert( escape("who are ü?") );

returns who%20are%20%FC%3F

Any suggestions how to get as3 to return escaped special characters as javascript is? Why is as3 apparently choking?

(here is a good reference: http://www.ultrashock./forums/actionscript/as3-escape-vs-as2-escape-122046.html )

Share Improve this question edited Feb 16, 2009 at 19:53 jedierikb asked Feb 16, 2009 at 15:52 jedierikbjedierikb 13.1k24 gold badges101 silver badges171 bronze badges 4
  • What I get with flex 3.0 is this: who%20are%20%FC%3F Isn't this what you want? Can you recheck? This is with a demo AIR app (and I am running Flex 3.0)! – dirkgently Commented Feb 16, 2009 at 16:17
  • Unfortunately, my trace statements are "who%20are%20%uFFFD%3F" (using flex3). – jedierikb Commented Feb 16, 2009 at 19:15
  • The code point %uFFFD flag tells you 'ü' did not get saved correctly. Did you make any changes to the locale? I believe that you are looking at console output. – dirkgently Commented Feb 16, 2009 at 19:36
  • I didn't change the locale... however, it looks like what i am looking for is utf-8 pliant encodeURIComponent for browser patibility (which as3 isn't giving me either. i get "who%20are%20%EF%BF%BD%3F") – jedierikb Commented Feb 16, 2009 at 19:48
Add a ment  | 

2 Answers 2

Reset to default 5

Looks like AS is escaping the string as UTF-16, while the Javascript example is escaping as UTF-8. escape doesn't define how to deal with non-ascii characters, and so it's been deprecated as of JavaScript 1.5. You should use the function encodeURIComponent instead, which is defined as escaping as UTF-8 - This should be consistent across different implementations. If you require the AS behaviour, I don't think there is a native function in Javascript, but you can use the functions provided here.

Although my IDE (intellij) was displaying, saving, and loading special characters, they were being saved in 1252. Switching to UTF-8 has fixed this.

发布评论

评论列表(0)

  1. 暂无评论