{"id":357,"date":"2006-06-03T16:06:58","date_gmt":"2006-06-03T08:06:58","guid":{"rendered":"http:\/\/fdream.net\/blog\/article\/357.aspx"},"modified":"2022-01-30T09:51:12","modified_gmt":"2022-01-30T01:51:12","slug":"%e8%ae%a1%e7%ae%97%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%a1%a8%e8%be%be%e5%bc%8f%e7%9a%84%e5%87%bd%e6%95%b0as%e7%89%88","status":"publish","type":"post","link":"https:\/\/fdream.net\/blog\/article\/357","title":{"rendered":"\u8ba1\u7b97\u5b57\u7b26\u4e32\u8868\u8fbe\u5f0f\u7684\u51fd\u6570(AS\u7248)"},"content":{"rendered":"\n<p>\u5148\u5e9f\u8bdd\u51e0\u53e5\uff1aAS\u4e2d\u7684\u6d6e\u70b9\u6570\u8ba1\u7b97\u8bef\u5dee\u4e5f\u771f\u662f\u5f88\u6709\u8da3\uff0c\u4f8b\u5982\uff1a6.4-6.3=0.100000000000001\uff0c\u8fd9\u662f\u5728Flash 8\u4e2d\u8fd0\u884c\u7684\u7ed3\u679c\uff0c\u9644\u56fe\u4e00\u5f20\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/fdream.net\/blog\/wp-content\/uploads\/2006\/06\/41s7_as.gif\" alt=\"\"\/><\/figure>\n\n\n\n<p><b>evalString \u51fd\u6570\u4ecb\u7ecd\uff1a<\/b><br \/>evalString(expression:String) : Number<\/p>\n\n\n\n<p>expression \u4e3a\u4e00\u4e2a\u7b97\u672f\u8868\u8fbe\u5f0f\uff0c\u8be5\u51fd\u6570\u5c06\u8ba1\u7b97\u6b64\u8868\u8fbe\u5f0f\u7684\u503c\uff0c\u5e76\u8fd4\u56de\u8ba1\u7b97\u7ed3\u679c\u3002\u6b64\u8868\u8fbe\u5f0f\u4ec5\u9650\u4e8e\u7b80\u5355\u7684\uff0b\u3001\uff0d\u3001\u00d7\u3001\u00f7\u4ee5\u53ca\u5e26\u62ec\u53f7\u7684\u8fd0\u7b97\uff0c\u8868\u8fbe\u5f0f\u4e2d\u4e0d\u5f97\u6709\u5176\u4ed6\u7b26\u53f7\uff0c\u5305\u62ec\u7a7a\u683c\u3002\u8868\u8fbe\u5f0f\u4e2d\u7684<b>\u6570\u5b57\u4e0d\u4ec5\u9650\u4e8e\u4e00\u4f4d\u6574\u6570\uff0c\u4e5f\u53ef\u4e3a\u591a\u4f4d\u6574\u6570\uff0c\u751a\u81f3\u662f\u5c0f\u6570<\/b>\u3002<\/p>\n\n\n\n<p><b>\u53c2\u6570<\/b><br \/>expression:String &#8211; \u4e00\u4e2a\u5b57\u7b26\u4e32\u8868\u8fbe\u5f0f\u3002<\/p>\n\n\n\n<p><b>\u8fd4\u56de<\/b><br \/>Number &#8211; \u4e00\u4e2a\u6570\u503c\u3002<\/p>\n\n\n\n<p><b>\u793a\u4f8b<\/b><\/p>\n\n\n\n<p>var infix:String = &#8220;(48-20*(6.2-5))\/(18-15)&#8221;;<br \/>trace(evalString(infix)); \/\/output 8<\/p>\n\n\n\n<p><b>\u51fd\u6570\u7b97\u6cd5\u601d\u60f3<\/b><\/p>\n\n\n\n<p>\u7b97\u6cd5\u601d\u60f3\u548c\u4e0a\u4e00\u7bc7<a title=\"\u300a\u628a\u4e2d\u7f00\u8868\u8fbe\u5f0f\u8f6c\u5316\u4e3a\u540e\u7f00\u8868\u8fbe\u5f0f\u300b\" href=\"http:\/\/fdream.net\/blog\/blogview.asp?logID=356\" target=\"_blank\" rel=\"noopener\">\u300a\u628a\u4e2d\u7f00\u8868\u8fbe\u5f0f\u8f6c\u5316\u4e3a\u540e\u7f00\u8868\u8fbe\u5f0f\u300b<\/a>\u4e2d\u6240\u8868\u8ff0\u7684\u601d\u60f3\u57fa\u672c\u4e00\u81f4\uff0c\u53ea\u662f\u5728\u626b\u63cf\u6570\u636e\u4ee5\u53ca\u8fd0\u7b97\u7b26\u9000\u6808\u65f6\u5904\u7406\u65b9\u6cd5\u4e0d\u540c\u3002<\/p>\n\n\n\n<p>\u5728\u626b\u63cf\u5b57\u7b26\u4e32\u65f6\uff0c\u82e5\u662f\u6570\u5b57\uff0c\u5219\u52a0\u5230\u4e00\u4e2a\u5b57\u7b26\u4e32\u540e\u9762\uff0c\u540c\u65f6\u626b\u63cf\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff0c\u82e5\u4e0d\u662f\u6570\u5b57\u5b57\u7b26\u4e5f\u4e0d\u662f\u5c0f\u6570\u70b9\uff0c\u5219\u628a\u5f53\u524d\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u5b57\u538b\u5165\u6570\u5b57\u6808\u3002<\/p>\n\n\n\n<p>\u5728\u9047\u5230\u8fd0\u7b97\u7b26\u9700\u8981\u9000\u6808\u65f6\uff0c\u4ece\u6570\u5b57\u6808\u4e2d\u53d6\u51fa\u6808\u9876\u7684\u4e24\u4e2a\u6570\u5b57\uff0c\u548c\u9000\u6808\u8fd0\u7b97\u7b26\u4e00\u8d77\u8fdb\u884c\u8fd0\u7b97\uff0c\u5e76\u628a\u8ba1\u7b97\u7ed3\u679c\u538b\u5165\u6570\u5b57\u6808\u4e2d\uff0c\u4f9d\u6b21\u5faa\u73af\uff0c\u76f4\u5230\u65e0\u987b\u9000\u6808\u3002\u626b\u63cf\u5b8c\u6210\u540e\uff0c\u9000\u6808\u8fd0\u7b97\u7b26\uff0c\u5e76\u4f9d\u6b21\u548c\u6570\u5b57\u6808\u4e2d\u6808\u9876\u7684\u6570\u5b57\u8fdb\u884c\u8fd0\u7b97\uff0c\u76f4\u81f3\u8fd0\u7b97\u7b26\u6808\u4e3a\u7a7a\u3002<\/p>\n\n\n\n<p>\u51fd\u6570\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/********************************************\/\n\/* Calculate the value of a string *\/\n\/* Example: *\/\n\/* var infix:String = \"(12.2-6.2)\/(8-5)\"; *\/\n\/* trace(evalString(infix)); \/\/output 2 *\/\n\/********************************************\/\n\/* Please keep this info when you quote *\/\n\/* www.afdream.com *\/\n\/* Author:Fdream *\/\n\/* Fdream All Rights Reserved *\/\n\/********************************************\/\n\nfunction evalString(infix:String) {\nvar opArray:Array = new Array();\n\n\/\/\u6808\u5e95\u6807\u8bb0\nopArray[0] = '@';\nvar op:Number = 1;\nvar postfix:Array = new Array();\nvar post:Number = 0;\n\n\/\/\u4fdd\u5b58\u8ba1\u7b97\u7ed3\u679c\nvar res:Number = 0;\n\nvar i, j;\nvar tempString:String = new String();\n\n\/\/\u8ba1\u7b97\u4e24\u4e2a\u6570\nfunction Caculate(opSign:String) {\nif (opSign == '+') {\nres = postfix[post-2]+postfix[post-1];\n} else if (opSign == '-') {\nres = postfix[post-2]-postfix[post-1];\n} else if (opSign == '*') {\nres = postfix[post-2]*postfix[post-1];\n} else if (opSign == '\/') {\nif (!postfix[post-1]) {\ntrace(\"Expression Error!\");\n} else {\nres = postfix[post-2]\/postfix[post-1];\n}\n}\npostfix[post-1] = 0;\npostfix[post-2] = res;\npost--;\n}\n\n\/\/\u626b\u63cf\u4e2d\u7f00\u8868\u8fbe\u5f0f\nfor (i=0; i&lt;infix.length; i++)=\"\" {&lt;br=\"\"&gt; switch (infix.charAt(i)) {\n\/\/\u5de6\u62ec\u53f7\u5c31\u76f4\u63a5\u5165\u6808\ncase '(' :\nopArray[op] = infix.charAt(i);\nop++;\nbreak;\n\/\/\u53f3\u62ec\u53f7\u5219\u9000\u6808\u8ba1\u7b97\uff0c\u76f4\u5230\u9047\u89c1\u4e00\u4e2a\u5de6\u62ec\u53f7\ncase ')' :\nfor (j=op-1; j&gt;0; j--) {\nif (opArray[j] != '(') {\nCaculate(opArray[j]);\nopArray[j] = '#';\n} else {\nopArray[j] = '#';\nbreak;\n}\n}\nop = j;\nbreak;\ncase '*' :\ncase '\/' :\n\/\/\u5982\u679c\u6808\u9876\u7684\u8fd0\u7b97\u7b26\u4e3a*\u6216\/\uff0c\u5219\u5148\u9000\u6808\uff0c\u518d\u5165\u6808\uff0c\u5426\u5219\u76f4\u63a5\u5165\u6808\nif (opArray[op-1] == '*') {\nop--;\nCaculate(opArray[op]);\nopArray[op] = '#';\n} else if (opArray[op-1] == '\/') {\nop--;\nCaculate(opArray[op]);\nopArray[op] = '#';\n}\nopArray[op] = infix.charAt(i);\nop++;\nbreak;\ncase '+' :\ncase '-' :\n\/\/\u5982\u679c\u6808\u9876\u7684\u8fd0\u7b97\u7b26\u4e0d\u662f\u5de6\u62ec\u53f7\u4e5f\u4e0d\u662f\u6808\u5e95\uff0c\u5219\u5148\u9000\u6808\u8ba1\u7b97\uff0c\u518d\u5165\u6808\nif (opArray[op-1] != '(' &amp;&amp; opArray[op-1] != '@') {\nop--;\nCaculate(opArray[op]);\nopArray[op] = '#';\n}\nopArray[op] = infix.charAt(i);\nop++;\nbreak;\ndefault :\n\/\/\u5982\u679c\u662f\u6570\u5b57\u5b57\u7b26\u6216\u8005\u5c0f\u6570\u70b9\u5219\u8f6c\u5316\u4e3a\u6570\u5b57\u5b58\u5165\u6570\u7ec4\n\/\/\u5982\u679c\u4e0b\u4e00\u4e2a\u5b57\u7b26\u662f\u8fd0\u7b97\u7b26\u5219\u628a\u5f53\u524d\u6570\u5b57\u5b58\u5165\u6570\u7ec4\ntempString += infix.charAt(i);\nvar temp:String = new String();\ntemp = infix.charAt(i+1);\nif (temp != '.' &amp;&amp; (temp&gt;'9' || temp&lt;'0')) {\npostfix[post] = parseFloat(tempString);\npost++;\ntempString = \"\";\n}\n\/\/trace(postfix);\n}\n}&lt;\/infix.length;&gt;\n\n\/\/\u626b\u63cf\u5b8c\u6210\uff0c\u5168\u90e8\u9000\u6808\nfor (j=op-1; j&gt;0; j--) {\nif (opArray[j] != '@') {\nCaculate(opArray[j]);\nopArray[j] = '#';\n} else {\nbreak;\n}\n}\n\/\/\u8fd4\u56de\u7ed3\u679c\nreturn postfix[0];\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u5e9f\u8bdd\u51e0\u53e5\uff1aAS\u4e2d\u7684\u6d6e\u70b9\u6570\u8ba1\u7b97\u8bef\u5dee\u4e5f\u771f\u662f\u5f88\u6709\u8da3\uff0c\u4f8b\u5982\uff1a6.4-6.3=0.100000000000001\uff0c\u8fd9\u662f\u5728Flash 8\u4e2d\u8fd0\u884c\u7684\u7ed3\u679c\uff0c\u9644\u56fe\u4e00\u5f20\uff1a evalString \u51fd\u6570\u4ecb\u7ecd\uff1aevalString(expression:String) : Number expression \u4e3a\u4e00\u4e2a\u7b97\u672f\u8868\u8fbe\u5f0f\uff0c\u8be5\u51fd\u6570\u5c06\u8ba1\u7b97\u6b64\u8868\u8fbe\u5f0f\u7684\u503c\uff0c\u5e76\u8fd4\u56de\u8ba1\u7b97\u7ed3\u679c\u3002\u6b64\u8868\u8fbe\u5f0f\u4ec5\u9650\u4e8e\u7b80\u5355\u7684\uff0b\u3001\uff0d\u3001\u00d7\u3001\u00f7\u4ee5\u53ca\u5e26\u62ec\u53f7\u7684\u8fd0\u7b97\uff0c\u8868\u8fbe\u5f0f\u4e2d\u4e0d\u5f97\u6709\u5176\u4ed6\u7b26\u53f7\uff0c\u5305\u62ec\u7a7a\u683c\u3002\u8868\u8fbe\u5f0f\u4e2d\u7684\u6570\u5b57\u4e0d\u4ec5\u9650\u4e8e\u4e00\u4f4d\u6574\u6570\uff0c\u4e5f\u53ef\u4e3a\u591a\u4f4d\u6574\u6570\uff0c\u751a\u81f3\u662f\u5c0f\u6570\u3002 \u53c2\u6570expression:String &#8211; \u4e00\u4e2a\u5b57\u7b26\u4e32\u8868\u8fbe\u5f0f\u3002 \u8fd4\u56deNumber &#8211; \u4e00\u4e2a\u6570\u503c\u3002 \u793a\u4f8b var infix:String = &#8220;(48-20*(6.2-5))\/(18-15)&#8221;;trace(evalString(infix)); \/\/output 8 \u51fd\u6570\u7b97\u6cd5\u601d\u60f3 \u7b97\u6cd5\u601d\u60f3\u548c\u4e0a\u4e00\u7bc7\u300a\u628a\u4e2d\u7f00\u8868\u8fbe\u5f0f\u8f6c\u5316\u4e3a\u540e\u7f00\u8868\u8fbe\u5f0f\u300b\u4e2d\u6240\u8868\u8ff0\u7684\u601d\u60f3\u57fa\u672c\u4e00\u81f4\uff0c\u53ea\u662f\u5728\u626b\u63cf\u6570\u636e\u4ee5\u53ca\u8fd0\u7b97\u7b26\u9000\u6808\u65f6\u5904\u7406\u65b9\u6cd5\u4e0d\u540c\u3002 \u5728\u626b\u63cf\u5b57\u7b26\u4e32\u65f6\uff0c\u82e5\u662f\u6570\u5b57\uff0c\u5219\u52a0\u5230\u4e00\u4e2a\u5b57\u7b26\u4e32\u540e\u9762\uff0c\u540c\u65f6\u626b\u63cf\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff0c\u82e5\u4e0d\u662f\u6570\u5b57\u5b57\u7b26\u4e5f\u4e0d\u662f\u5c0f\u6570\u70b9\uff0c\u5219\u628a\u5f53\u524d\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u5b57\u538b\u5165\u6570\u5b57\u6808\u3002 \u5728\u9047\u5230\u8fd0\u7b97\u7b26\u9700\u8981\u9000\u6808\u65f6\uff0c\u4ece\u6570\u5b57\u6808\u4e2d\u53d6\u51fa\u6808\u9876\u7684\u4e24\u4e2a\u6570\u5b57\uff0c\u548c\u9000\u6808\u8fd0\u7b97\u7b26\u4e00\u8d77\u8fdb\u884c\u8fd0\u7b97\uff0c\u5e76\u628a\u8ba1\u7b97\u7ed3\u679c\u538b\u5165\u6570\u5b57\u6808\u4e2d\uff0c\u4f9d\u6b21\u5faa\u73af\uff0c\u76f4\u5230\u65e0\u987b\u9000\u6808\u3002\u626b\u63cf\u5b8c\u6210\u540e\uff0c\u9000\u6808\u8fd0\u7b97\u7b26\uff0c\u5e76\u4f9d\u6b21\u548c\u6570\u5b57\u6808\u4e2d\u6808\u9876\u7684\u6570\u5b57\u8fdb\u884c\u8fd0\u7b97\uff0c\u76f4\u81f3\u8fd0\u7b97\u7b26\u6808\u4e3a\u7a7a\u3002 \u51fd\u6570\u4ee3\u7801\u5982\u4e0b\uff1a \/********************************************\/ \/* Calculate the value of a string *\/ \/* Example: *\/ \/* var infix:String = &#8220;(12.2-6.2)\/(8-5)&#8221;; *\/ \/* trace(evalString(infix)); \/\/output 2 *\/ \/********************************************\/ \/* Please keep this info &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[216,78,212],"class_list":["post-357","post","type-post","status-publish","format-standard","hentry","category-coding","tag-ActionScript","tag-AS","tag-212"],"views":32424,"_links":{"self":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/comments?post=357"}],"version-history":[{"count":0,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/357\/revisions"}],"wp:attachment":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/media?parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/categories?post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/tags?post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}