{"id":488,"date":"2010-03-08T10:28:30","date_gmt":"2010-03-08T17:28:30","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=2798"},"modified":"2010-03-08T10:28:30","modified_gmt":"2010-03-08T17:28:30","slug":"urlvariables-replacement","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=488","title":{"rendered":"URLVariables Replacement"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nfunction decode(str:String):Object {\r\n\tvar vars:Object={};\r\n\tvar parse:Array =str.split(&quot;&amp;&quot;);\r\n\tvar i:int=0;\r\n\tfor (i = 0; i&lt;parse.length; i++) {\r\n\t\tvar pair:Array=parse&#x5B;i].split(&quot;=&quot;);\r\n\t\tif (pair.length==2) {\r\n\t\t\tvars&#x5B;pair&#x5B;0]]=pair&#x5B;1];\r\n\t\t}\r\n\t}\r\n\treturn vars;\r\n}\r\n\r\nvar nameValuePairs=&quot;one=1&amp;&amp;two=\u00e9llo&amp;three=1000&amp;four=0xFF0000&quot;;\r\nvar parsed:Object=decode(nameValuePairs);\r\n\r\ntrace(parsed.one);\r\ntrace(parsed.two);\r\ntrace(parsed.three);\r\ntrace(parsed.four);\r\n\r\n\/*outputs: \r\n1\r\n\u00e9llo\r\n1000\r\n0xFF0000\r\n*\/\r\n<\/pre>\n<p>Well not exactly a URLVariables replacement, but I often use the URLVariables.decode() function and find that its very picky&#8230; like if there is an extra &#038; or something it freaks out and breaks, or if there are line returns. As a quick and simple solution the other day I wrote this function into part of a class (Model class) that I was working on. Fixed the problem and even handles Spanish characters nicely.<\/p>\n<p>There is plenty of room for improvement with this simple function&#8230; feel free to post improvements in the comments.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>function decode(str:String):Object { var vars:Object={}; var parse:Array =str.split(&quot;&amp;&quot;); var i:int=0; for (i = 0; i&lt;parse.length; i++) { var pair:Array=parse&#x5B;i].split(&quot;=&quot;); if (pair.length==2) { vars&#x5B;pair&#x5B;0]]=pair&#x5B;1]; } } return vars; } var nameValuePairs=&quot;one=1&amp;&amp;two=\u00e9llo&amp;three=1000&amp;four=0xFF0000&quot;; var parsed:Object=decode(nameValuePairs); trace(parsed.one); trace(parsed.two); trace(parsed.three); trace(parsed.four); \/*outputs: 1 \u00e9llo 1000 0xFF0000 *\/ Well not exactly a URLVariables replacement, but I often use the URLVariables.decode() function [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[88,20,21],"tags":[3,14,4],"class_list":["post-488","post","type-post","status-publish","format-standard","hentry","category-external-data","category-string-manipulation","category-strings","tag-actionscript","tag-as3","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=488"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/488\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}