{"id":40831,"date":"2024-12-01T08:54:06","date_gmt":"2024-12-01T00:54:06","guid":{"rendered":"https:\/\/fwq.ai\/blog\/40831\/"},"modified":"2024-12-01T08:54:06","modified_gmt":"2024-12-01T00:54:06","slug":"golang-%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%bd%ac-byte-%e4%b8%ba%e4%bd%95%e6%9c%89%e6%97%b6%e7%bb%93%e6%9e%9c%e4%b8%8d%e5%90%8c%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/40831\/","title":{"rendered":"Golang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u6709\u65f6\u7ed3\u679c\u4e0d\u540c\uff1f"},"content":{"rendered":"<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aGolang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u6709\u65f6\u7ed3\u679c\u4e0d\u540c\uff1f \u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241029\/17301681396720454b93269.jpg\" class=\"aligncenter\" title=\"Golang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u6709\u65f6\u7ed3\u679c\u4e0d\u540c\uff1f\u63d2\u56fe\" alt=\"Golang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u6709\u65f6\u7ed3\u679c\u4e0d\u540c\uff1f\u63d2\u56fe\" \/>,<br \/>\n<strong>golang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u4e0d\u540c\uff1f<\/strong>,\u5f53\u4f7f\u7528 []byte(str) \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u8282\u5207\u7247\u65f6\uff0c\u7ed3\u679c\u53ef\u80fd\u4e0e\u76f4\u63a5\u58f0\u660e\u5b57\u8282\u5207\u7247\u4e0d\u540c\u3002,\u4e3e\u4e2a\u4f8b\u5b50\uff0c \u5b57\u7b26 &#8216;xa0&#8217;\uff08\u7a7a\u683c\u5b57\u7b26\uff09\u5728\u8f6c\u6362\u4e3a\u5b57\u8282\u5207\u7247\u540e\uff0c\u8f93\u51fa\u7684\u662f [194 129]\uff0c\u800c\u76f4\u63a5\u58f0\u660e\u5b57\u8282\u5207\u7247 [129] \u7684\u8bdd\uff0c\u8f93\u51fa\u7684\u5374\u662f [129]\u3002,\u8fd9\u662f\u56e0\u4e3a\uff1a,\u56e0\u6b64\uff0c\u5f53\u4f7f\u7528 []byte(str) \u8f6c\u6362\u4e3a\u5b57\u8282\u5207\u7247\u65f6\uff0c\u4f1a\u76f4\u63a5\u8f93\u51fa\u5b57\u7b26\u7684 UTF-8 \u7f16\u7801\u3002,\u800c\u76f4\u63a5\u58f0\u660e\u5b57\u8282\u5207\u7247\uff0c\u610f\u5473\u7740\u6307\u5b9a\u4e86\u56fa\u5b9a\u957f\u5ea6\uff0c\u6b64\u65f6 go \u4f1a\u6839\u636e\u957f\u5ea6\u5c06\u5b57\u8282\u586b\u5145\u5230\u5207\u7247\u4e2d\u3002\u5982\u679c\u957f\u5ea6\u4e0d\u5339\u914d\u5b57\u7b26\u7684 UTF-8 \u7f16\u7801\u5bbd\u5ea6\uff0c\u5c31\u4f1a\u5bfc\u81f4\u7ed3\u679c\u4e0d\u540c\u3002,\u8981\u4fdd\u8bc1\u8f6c\u6362\u7ed3\u679c\u4e00\u81f4\uff0c\u53ef\u4ee5\u4f7f\u7528 []rune(str) \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a rune \u5207\u7247\u3002rune \u5207\u7247\u5b58\u50a8\u7684\u662f\u5b57\u7b26\u4e32\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u7684 Unicode \u7801\u70b9\uff0c\u4e0d\u4f1a\u53d7\u5230 UTF-8 \u7f16\u7801\u7684\u5f71\u54cd\u3002,\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300aGolang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u6709\u65f6\u7ed3\u679c\u4e0d\u540c\uff1f \u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8golang\u5b66\u4e60\u7f51\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591aGolang\u77e5\u8bc6\uff01,\u5b57\u7b26 &#8216;xa0&#8217; \u7684 UTF-8 \u7f16\u7801\u662f [194 129]\uff0c\u4ee3\u8868\u4e00\u4e2a\u5bbd\u5ea6\u4e3a 2 \u4e2a\u5b57\u8282\u7684\u5b57\u7b26\u3002,go \u4e2d\u7684\u5b57\u7b26\u4e32\u5b58\u50a8\u7684\u662f UTF-8 \u7f16\u7801\u7684\u5b57\u8282\u5207\u7247\u3002,golang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u4e0d\u540c\uff1f,\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aGolang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u6709\u65f6\u7ed3\u679c\u4e0d\u540c\uff1f \u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002,<br \/>\n<b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>Golang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u6709\u65f6\u7ed3\u679c\u4e0d\u540c\uff1f <\/span><\/p>\n<h1>Golang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u6709\u65f6\u7ed3\u679c\u4e0d\u540c\uff1f <\/h1>\n<p><span>2024-10-29 10:15:55<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aGolang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u6709\u65f6\u7ed3\u679c\u4e0d\u540c\uff1f \u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241029\/17301681396720454b93269.jpg\" class=\"aligncenter\" title=\"Golang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u6709\u65f6\u7ed3\u679c\u4e0d\u540c\uff1f\u63d2\u56fe\" alt=\"Golang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u6709\u65f6\u7ed3\u679c\u4e0d\u540c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>golang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u4e0d\u540c\uff1f<\/strong><\/p>\n<p>\u5f53\u4f7f\u7528 []byte(str) \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u8282\u5207\u7247\u65f6\uff0c\u7ed3\u679c\u53ef\u80fd\u4e0e\u76f4\u63a5\u58f0\u660e\u5b57\u8282\u5207\u7247\u4e0d\u540c\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c \u5b57\u7b26 &#8216;xa0&#8217;\uff08\u7a7a\u683c\u5b57\u7b26\uff09\u5728\u8f6c\u6362\u4e3a\u5b57\u8282\u5207\u7247\u540e\uff0c\u8f93\u51fa\u7684\u662f [194 129]\uff0c\u800c\u76f4\u63a5\u58f0\u660e\u5b57\u8282\u5207\u7247 [129] \u7684\u8bdd\uff0c\u8f93\u51fa\u7684\u5374\u662f [129]\u3002<\/p>\n<p>\u8fd9\u662f\u56e0\u4e3a\uff1a<\/p>\n<ul>\n<li>go \u4e2d\u7684\u5b57\u7b26\u4e32\u5b58\u50a8\u7684\u662f UTF-8 \u7f16\u7801\u7684\u5b57\u8282\u5207\u7247\u3002<\/li>\n<li>\u5b57\u7b26 &#8216;xa0&#8217; \u7684 UTF-8 \u7f16\u7801\u662f [194 129]\uff0c\u4ee3\u8868\u4e00\u4e2a\u5bbd\u5ea6\u4e3a 2 \u4e2a\u5b57\u8282\u7684\u5b57\u7b26\u3002<\/li>\n<\/ul>\n<p>\u56e0\u6b64\uff0c\u5f53\u4f7f\u7528 []byte(str) \u8f6c\u6362\u4e3a\u5b57\u8282\u5207\u7247\u65f6\uff0c\u4f1a\u76f4\u63a5\u8f93\u51fa\u5b57\u7b26\u7684 UTF-8 \u7f16\u7801\u3002<\/p>\n<p>\u800c\u76f4\u63a5\u58f0\u660e\u5b57\u8282\u5207\u7247\uff0c\u610f\u5473\u7740\u6307\u5b9a\u4e86\u56fa\u5b9a\u957f\u5ea6\uff0c\u6b64\u65f6 go \u4f1a\u6839\u636e\u957f\u5ea6\u5c06\u5b57\u8282\u586b\u5145\u5230\u5207\u7247\u4e2d\u3002\u5982\u679c\u957f\u5ea6\u4e0d\u5339\u914d\u5b57\u7b26\u7684 UTF-8 \u7f16\u7801\u5bbd\u5ea6\uff0c\u5c31\u4f1a\u5bfc\u81f4\u7ed3\u679c\u4e0d\u540c\u3002<\/p>\n<p>\u8981\u4fdd\u8bc1\u8f6c\u6362\u7ed3\u679c\u4e00\u81f4\uff0c\u53ef\u4ee5\u4f7f\u7528 []rune(str) \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a rune \u5207\u7247\u3002rune \u5207\u7247\u5b58\u50a8\u7684\u662f\u5b57\u7b26\u4e32\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u7684 Unicode \u7801\u70b9\uff0c\u4e0d\u4f1a\u53d7\u5230 UTF-8 \u7f16\u7801\u7684\u5f71\u54cd\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300aGolang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u6709\u65f6\u7ed3\u679c\u4e0d\u540c\uff1f \u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8golang\u5b66\u4e60\u7f51\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591aGolang\u77e5\u8bc6\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u5982\u4f55\u4f7f\u7528\u963f\u91cc OSS \u8fdc\u7a0b\u6587\u4ef6\u4e0b\u8f7d\u529f\u80fd\u5728 Django \u5e94\u7528\u4e2d\u5b9e\u73b0\u6587\u4ef6\u4e0b\u8f7d\uff1f\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   CSS \u5c5e\u6027\u63a2\u7d22\uff1a\u5982\u4f55\u8ba9\u5143\u7d20\u5f62\u540c\u865a\u8bbe\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aGolang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u6709\u65f6\u7ed3\u679c\u4e0d\u540c\uff1f \u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002, , golang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u4e0d\u540c\uff1f,\u5f53\u4f7f\u7528 []byte(str) \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u8282\u5207\u7247\u65f6\uff0c\u7ed3\u679c\u53ef\u80fd\u4e0e\u76f4\u63a5\u58f0\u660e\u5b57\u8282\u5207\u7247\u4e0d\u540c\u3002,\u4e3e\u4e2a\u4f8b\u5b50\uff0c \u5b57\u7b26 &#8216;xa0&#8217;\uff08\u7a7a\u683c\u5b57\u7b26\uff09\u5728\u8f6c\u6362\u4e3a\u5b57\u8282\u5207\u7247\u540e\uff0c\u8f93\u51fa\u7684\u662f [194 129]\uff0c\u800c\u76f4\u63a5\u58f0\u660e\u5b57\u8282\u5207\u7247 [129] \u7684\u8bdd\uff0c\u8f93\u51fa\u7684\u5374\u662f [129]\u3002,\u8fd9\u662f\u56e0\u4e3a\uff1a,\u56e0\u6b64\uff0c\u5f53\u4f7f\u7528 []byte(str) \u8f6c\u6362\u4e3a\u5b57\u8282\u5207\u7247\u65f6\uff0c\u4f1a\u76f4\u63a5\u8f93\u51fa\u5b57\u7b26\u7684 UTF-8 \u7f16\u7801\u3002,\u800c\u76f4\u63a5\u58f0\u660e\u5b57\u8282\u5207\u7247\uff0c\u610f\u5473\u7740\u6307\u5b9a\u4e86\u56fa\u5b9a\u957f\u5ea6\uff0c\u6b64\u65f6 go \u4f1a\u6839\u636e\u957f\u5ea6\u5c06\u5b57\u8282\u586b\u5145\u5230\u5207\u7247\u4e2d\u3002\u5982\u679c\u957f\u5ea6\u4e0d\u5339\u914d\u5b57\u7b26\u7684 UTF-8 \u7f16\u7801\u5bbd\u5ea6\uff0c\u5c31\u4f1a\u5bfc\u81f4\u7ed3\u679c\u4e0d\u540c\u3002,\u8981\u4fdd\u8bc1\u8f6c\u6362\u7ed3\u679c\u4e00\u81f4\uff0c\u53ef\u4ee5\u4f7f\u7528 []rune(str) \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a rune \u5207\u7247\u3002rune \u5207\u7247\u5b58\u50a8\u7684\u662f\u5b57\u7b26\u4e32\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u7684 Unicode \u7801\u70b9\uff0c\u4e0d\u4f1a\u53d7\u5230 UTF-8 \u7f16\u7801\u7684\u5f71\u54cd\u3002,\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300aGolang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u6709\u65f6\u7ed3\u679c\u4e0d\u540c\uff1f \u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8golang\u5b66\u4e60\u7f51\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591aGolang\u77e5\u8bc6\uff01,\u5b57\u7b26 &#8216;xa0&#8217; \u7684 UTF-8 \u7f16\u7801\u662f [194 129]\uff0c\u4ee3\u8868\u4e00\u4e2a\u5bbd\u5ea6\u4e3a 2 \u4e2a\u5b57\u8282\u7684\u5b57\u7b26\u3002,go \u4e2d\u7684\u5b57\u7b26\u4e32\u5b58\u50a8\u7684\u662f UTF-8 \u7f16\u7801\u7684\u5b57\u8282\u5207\u7247\u3002,golang \u5b57\u7b26\u4e32\u8f6c []byte \u4e3a\u4f55\u4e0d\u540c\uff1f,\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aGolang \u5b57\u7b26\u4e32\u8f6c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-40831","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/40831","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=40831"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/40831\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=40831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=40831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=40831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}