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.com/forums/actionscript/as3-escape-vs-as2-escape-122046.html )
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 .
尽管我的IDE(intellij)正在显示,保存和加载特殊字符,但它们仍保存在1252中。切换到UTF-8可以解决此问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.