{"id":1632,"date":"2024-12-05T12:52:48","date_gmt":"2024-12-05T04:52:48","guid":{"rendered":"https:\/\/thereisno.top\/?p=1632"},"modified":"2026-02-11T11:46:36","modified_gmt":"2026-02-11T03:46:36","slug":"x-%e5%bc%80%e5%a4%b4%e7%bc%96%e7%a0%81%e7%9a%84%e6%95%b0%e6%8d%ae%e8%a7%a3%e7%a0%81%e6%88%90%e4%b8%ad%e6%96%87","status":"publish","type":"post","link":"https:\/\/thereisno.top\/?p=1632","title":{"rendered":"\\x\u00a0\u5f00\u5934\u7f16\u7801\u7684\u6570\u636e\u89e3\u7801\u6210\u4e2d\u6587"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>Python&nbsp;\u89e3\u7801<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>b=b'\\xE8\\xA7\\xA3\\xE5\\x86\\xB3'\nb.decode('utf-8')\n'\u89e3\u51b3'<\/code><\/pre>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Java&nbsp;\u89e3\u7801<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public static void main(String&#91;] args) throws UnsupportedEncodingException{        \n    String utf8String = \"\\\\xE8\\\\xA7\\\\xA3\\\\xE5\\\\x86\\\\xB3\";\n    System.out.println(decodeUTF8Str(utf8String));    \n}\npublic static String decodeUTF8Str(String xStr) throws UnsupportedEncodingException {        \n    return URLDecoder.decode(xStr.replaceAll(\"\\\\\\\\x\", \"%\"), \"utf-8\");    \n}\u3000\n\u4ee5\u4e0a\u4ee3\u7801\u8f93\u51fa:\n\u89e3\u51b3\nProcess finished with exit code 0\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Javascript\u7f16\u89e3\u7801<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">function decode(str) {<br>return decodeURI(str.replace(\/\\\\x\/g,&#8221;%&#8221;));<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">decode(&#8216;\\\\xE8\\\\xA7\\\\xA3\\\\xE5\\\\x86\\\\xB3&#8217;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6216\u8005<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">function decode(str){<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var charIntStr= str.replace(\/\\\\x(\\w{2})\/g,function(_,$1){<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return parseInt($1,16)+&#8221;,&#8221; ;}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; charIntStr= charIntStr.substr(0,charIntStr.length-1);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var charIntArray= charIntStr.split(&#8220;,&#8221;);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var buffer = new Uint8Array(charIntArray);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var decoder = new TextDecoder(&#8216;utf-8&#8217;);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var result = decoder.decode(buffer);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; console.log(result);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">decode(&#8216;\\\\xE8\\\\xA7\\\\xA3\\\\xE5\\\\x86\\\\xB3&#8217;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u89e3\u7801\u274c\u53ea\u80fd\u83b7\u5f97acsii\u5b57\u7b26<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">function decode(str){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return str.replace(\/\\\\x(\\w{2})\/g,function(_,$1){ <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">               return String.fromCharCode(parseInt($1,16)) }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">        );<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">eg.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">decode(&#8216;\\xE8\\xA7\\xA3\\xE5\\x86\\xB3&#8217;)  \/\/\u89e3\u51b3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f16\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function encode(str){    \n     return str.replace(\/(\\w)\/g,function(_,$1){ \n         return \"\\\\x\"+ $1.charCodeAt(0).toString(16) }\n     );\n}\neg.\nencode(\"\u89e3\u51b3\")  \/\/\"\\xE8\\xA7\\xA3\\xE5\\x86\\xB3\"\n\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/activity.huaweicloud.com\/cps.html?fromacct=6d7bf5b928b847b3a50bbf7d7c439354&amp;utm_source=V1g3MDY4NTY=&amp;utm_medium=cps&amp;utm_campaign=201905\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"310\" src=\"https:\/\/thereisno.top\/wp-content\/uploads\/2024\/12\/hwFlex-1024x310.jpeg\" alt=\"\" class=\"wp-image-2428\" srcset=\"https:\/\/thereisno.top\/wp-content\/uploads\/2024\/12\/hwFlex-1024x310.jpeg 1024w, https:\/\/thereisno.top\/wp-content\/uploads\/2024\/12\/hwFlex-300x91.jpeg 300w, https:\/\/thereisno.top\/wp-content\/uploads\/2024\/12\/hwFlex-768x233.jpeg 768w, https:\/\/thereisno.top\/wp-content\/uploads\/2024\/12\/hwFlex.jpeg 1320w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><figcaption class=\"wp-element-caption\">Flexus L\u5b9e\u4f8b 2\u68382G2M \u7279\u4ef738\u51431\u5e74<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u6df1\u5165\u7406\u89e3<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u4e86\u89e3\u539f\u7406\uff0c\u63a8\u8350<a href=\"http:\/\/www.ruanyifeng.com\/blog\/2007\/10\/ascii_unicode_and_utf-8.html\">\u9605\u8bfb<\/a>\uff0cUTF-8\u662funicode\u7f16\u7801\u7684\u4e00\u79cd\u843d\u5730\u65b9\u6848\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>UTF-8\u662funicode\u7f16\u7801\u7684\u4e00\u79cd\u843d\u5730\u65b9\u6848\uff1a\nUnicode\u7b26\u53f7\u8303\u56f4      | UTF-8\u7f16\u7801\u65b9\u5f0f\n(\u5341\u516d\u8fdb\u5236)           | \uff08\u4e8c\u8fdb\u5236\uff09\n--------------------+---------------------------------------------\n0000 0000-0000 007F | 0xxxxxxx\n0000 0080-0000 07FF | 110xxxxx 10xxxxxx\n0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx\n0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\\x\u5bf9\u5e94\u7684\u662fUTF-8\u7f16\u7801\u7684\u6570\u636e\uff0c\u901a\u8fc7\u8f6c\u5316\u89c4\u5219\u53ef\u4ee5\u8f6c\u6362\u4e3aUnicode\u7f16\u7801\uff0c\u5c31\u80fd\u5f97\u5230\u5bf9\u5e94\u7684\u6c49\u5b57\uff0c\u8f6c\u6362\u89c4\u5219\u5f88\u7b80\u5355\uff0c\u5148\u5c06\\x\u53bb\u6389\uff0c\u8f6c\u6362\u4e3a\u6570\u5b57\uff0c\u7136\u540e\u8fdb\u884c\u5bf9\u5e94\u7684\u4f4d\u79fb\u64cd\u4f5c\u5373\u53ef\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\u5148\u8981\u5224\u65adutf-8\u7684\u4f4d\u6570\u3002\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u7684scala\u4ee3\u7801\u6df1\u5165\u4e86\u89e3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> val pattern = \"\"\"(\\d+\\.\\d+\\.\\d+\\.\\d+) \\- (\\S+) (\\S+) \\&#91;(&#91;^\\]]+)\\] \\\"(\\w+) (\\S+) \\S+\\\" (\\S+) (\\S+) \\\"(&#91;^\\\"]+)\\\" \\\"(&#91;^\\\"]+)\\\" \\\"(&#91;^\\\"]+)\\\" \\\"(&#91;^\\\"]+)\"\"\".r\n  val decodeDataPattern = \"\"\"(\\\\x(&#91;0-9A-Z]){2})+\"\"\".r\n  def decodeUtf8(utf8Str:String):String={\n    var data =   decodeDataPattern.replaceAllIn(utf8Str, m=&gt;{\n        var item = decodeXdata(m.toString())\n        item\n     }) \n     return data\n   }\n     \n   def decodeXdata(utf8Str:String):String={\n     var arr = utf8Str.split(\"\\\\\\\\x\")\n     var result = new StringBuilder()\n     var isMatchEnd = true\n     var matchIndex = 0\n     var currentWordLength = 0\n     var current = 0\n     var e0=0xe0;\n     \n     for(item &lt;-arr){\n        var str = item.trim\n        if(str.length()&gt;0){\n           var currentCode =  Integer.parseInt(str, 16);\n           if(isMatchEnd){\n             isMatchEnd = false\n             var and = currentCode &amp; e0;\n             if(and == 0xe0){\n                matchIndex = 1;\n                currentWordLength = 3;\n                current =  (currentCode &amp; 0x1f) &lt;&lt;12  \/\/ 3\u4f4d\u7f16\u7801\u7684\n             }else if(and==96){\n                matchIndex = 1;\n                currentWordLength = 2;\n                current =  (currentCode &amp; 0x1f) &lt;&lt;6 \/\/ 2\u4f4d\u7f16\u7801\u7684\n             }else{\n               current = currentCode  \/\/ 1\u4f4d\u7f16\u7801\u7684\n             }\n          }else{\n            matchIndex = matchIndex+1;\n            if(matchIndex == 2)\n            {\n              current+=(currentCode &amp; 0x3f) &lt;&lt;6\n            }else{\n               current+=(currentCode &amp; 0x3f) \n            }\n          }\n           if(matchIndex==currentWordLength){\n               var hex = Integer.toHexString(current)\n               hex = if(hex.length()&lt;4) \"\\\\u00\"+hex else \"\\\\u\"+hex  \/\/\u88650\n               result.append(new String(StringEscapeUtils.unescapeJava(hex).getBytes,\"utf-8\")) \n               current = 0\n               matchIndex=0\n               isMatchEnd = true\n           }\n        }\n     }\n     \n     return result.toString()\n   }\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Python&nbsp;\u89e3\u7801<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,44,14],"tags":[177,176,179,178,175],"class_list":["post-1632","post","type-post","status-publish","format-standard","hentry","category-java","category-javascript","category-python","tag-unicode","tag-utf8","tag-179","tag-178","tag-175"],"_links":{"self":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/1632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1632"}],"version-history":[{"count":8,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/1632\/revisions"}],"predecessor-version":[{"id":2801,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/1632\/revisions\/2801"}],"wp:attachment":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}