{"id":3730,"date":"2022-12-30T13:55:10","date_gmt":"2022-12-30T05:55:10","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3730"},"modified":"2022-12-30T13:55:10","modified_gmt":"2022-12-30T05:55:10","slug":"%e5%ad%b8%e7%bf%92go%e8%aa%9e%e8%a8%80%e4%b8%ad%e7%9a%84%e5%ad%97%e7%ac%a6%e9%9b%86%e8%bd%89%e6%8f%9b","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/go\/%e5%ad%b8%e7%bf%92go%e8%aa%9e%e8%a8%80%e4%b8%ad%e7%9a%84%e5%ad%97%e7%ac%a6%e9%9b%86%e8%bd%89%e6%8f%9b\/","title":{"rendered":"\u5b78\u7fd2Go\u8a9e\u8a00\u4e2d\u7684\u5b57\u7b26\u96c6\u8f49\u63db"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Go, \u5b57\u7b26\u96c6\u8f49\u63db\"><\/p>\n<p>Go \u8a9e\u8a00\u7684\u5b57\u7b26\u96c6\u8f49\u63db\u662f\u4e00\u500b\u975e\u5e38\u91cd\u8981\u7684\u6280\u8853\uff0c\u5b83\u53ef\u4ee5\u8b93\u6211\u5011\u5c07\u6587\u5b57\u5f9e\u4e00\u7a2e\u5b57\u7b26\u96c6\u8f49\u63db\u5230\u53e6\u4e00\u7a2e\u5b57\u7b26\u96c6\uff0c\u4ee5\u4fbf\u5728\u4e0d\u540c\u7684\u7cfb\u7d71\u4e4b\u9593\u4ea4\u63db\u6587\u5b57\u8cc7\u6599\u3002\u5728\u4eca\u5929\u7684\u7db2\u8def\u74b0\u5883\u4e2d\uff0c\u5b57\u7b26\u96c6\u8f49\u63db\u662f\u4e00\u500b\u975e\u5e38\u91cd\u8981\u7684\u6280\u8853\uff0c\u5b83\u53ef\u4ee5\u8b93\u6211\u5011\u5728\u4e0d\u540c\u7684\u7cfb\u7d71\u4e4b\u9593\u4ea4\u63db\u6587\u5b57\u8cc7\u6599\uff0c\u800c\u4e0d\u6703\u56e0\u70ba\u5b57\u7b26\u96c6\u7684\u4e0d\u540c\u800c\u5c0e\u81f4\u8cc7\u6599\u640d\u5931\u3002<\/p>\n<p>Go \u8a9e\u8a00\u63d0\u4f9b\u4e86\u4e00\u500b\u975e\u5e38\u65b9\u4fbf\u7684\u51fd\u5f0f\u5eab\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u8f15\u9b06\u5730\u5c0d\u5b57\u7b26\u96c6\u9032\u884c\u8f49\u63db\u3002Go \u8a9e\u8a00\u7684\u5b57\u7b26\u96c6\u8f49\u63db\u51fd\u5f0f\u5eab\u652f\u63f4\u591a\u7a2e\u5b57\u7b26\u96c6\uff0c\u5305\u62ec UTF-8\u3001GBK\u3001Big5 \u7b49\u7b49\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u8f15\u9b06\u5730\u5c0d\u5b57\u7b26\u96c6\u9032\u884c\u8f49\u63db\u3002<\/p>\n<h2>Go \u8a9e\u8a00\u5b57\u7b26\u96c6\u8f49\u63db\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>Go \u8a9e\u8a00\u7684\u5b57\u7b26\u96c6\u8f49\u63db\u51fd\u5f0f\u5eab\u63d0\u4f9b\u4e86\u4e00\u500b\u975e\u5e38\u7c21\u55ae\u7684 API\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u8f15\u9b06\u5730\u5c0d\u5b57\u7b26\u96c6\u9032\u884c\u8f49\u63db\u3002Go \u8a9e\u8a00\u7684\u5b57\u7b26\u96c6\u8f49\u63db\u51fd\u5f0f\u5eab\u63d0\u4f9b\u4e86\u5169\u500b\u51fd\u5f0f\uff1a<span style=\"color: #ff0000; font-weight: bold;\">ConvertString<\/span> \u548c <span style=\"color: #ff0000; font-weight: bold;\">ConvertBytes<\/span>\uff0c\u5206\u5225\u7528\u65bc\u5c0d\u5b57\u4e32\u548c\u5b57\u5143\u9663\u5217\u9032\u884c\u8f49\u63db\u3002<\/p>\n<p><!--more--><\/p>\n<h2>Go \u8a9e\u8a00\u5b57\u7b26\u96c6\u8f49\u63db\u7684\u7a0b\u5f0f\u7bc4\u4f8b<\/h2>\n<p>\u4e0b\u9762\u662f\u4e00\u500b\u7c21\u55ae\u7684\u7a0b\u5f0f\u7bc4\u4f8b\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u8f15\u9b06\u5730\u5c0d\u5b57\u7b26\u96c6\u9032\u884c\u8f49\u63db\uff1a<\/p>\n<pre class=\"brush: go\">\npackage main\n\nimport (\n    \"fmt\"\n    \"golang.org\/x\/text\/encoding\/simplifiedchinese\"\n    \"golang.org\/x\/text\/transform\"\n)\n\nfunc main() {\n    \/\/ \u5c07 UTF-8 \u7de8\u78bc\u7684\u5b57\u4e32\u8f49\u63db\u70ba GBK \u7de8\u78bc\n    utf8Str := \"\u4f60\u597d\uff0c\u4e16\u754c\uff01\"\n    gbkStr, _, _ := transform.String(simplifiedchinese.GBK.NewEncoder(), utf8Str)\n    fmt.Println(gbkStr)\n}\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4f7f\u7528 Go \u8a9e\u8a00\u7684\u5b57\u7b26\u96c6\u8f49\u63db\u51fd\u5f0f\u5eab\u5c07 UTF-8 \u7de8\u78bc\u7684\u5b57\u4e32\u8f49\u63db\u70ba GBK \u7de8\u78bc\uff0c\u8f38\u51fa\u7d50\u679c\u70ba\uff1a<\/p>\n<pre>\n\u4f60\u597d\uff0c\u4e16\u754c\uff01\n<\/pre>\n<p>\u901a\u904e\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\uff0c\u6211\u5011\u53ef\u4ee5\u770b\u5230 Go \u8a9e\u8a00\u7684\u5b57\u7b26\u96c6\u8f49\u63db\u51fd\u5f0f\u5eab\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u8f15\u9b06\u5730\u5c0d\u5b57\u7b26\u96c6\u9032\u884c\u8f49\u63db\uff0c\u800c\u4e0d\u9700\u8981\u81ea\u5df1\u5beb\u592a\u591a\u7684\u7a0b\u5f0f\u78bc\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>Go \u8a9e\u8a00\u7684\u5b57\u7b26\u96c6\u8f49\u63db\u51fd\u5f0f\u5eab\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u8f15\u9b06\u5730\u5c0d\u5b57\u7b26\u96c6\u9032\u884c\u8f49\u63db\uff0c\u800c\u4e0d\u9700\u8981\u81ea\u5df1\u5beb\u592a\u591a\u7684\u7a0b\u5f0f\u78bc\u3002Go \u8a9e\u8a00\u7684\u5b57\u7b26\u96c6\u8f49\u63db\u51fd\u5f0f\u5eab\u652f\u63f4\u591a\u7a2e\u5b57\u7b26\u96c6\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u8f15\u9b06\u5730\u5c0d\u5b57\u7b26\u96c6\u9032\u884c\u8f49\u63db\uff0c\u4ee5\u4fbf\u5728\u4e0d\u540c\u7684\u7cfb\u7d71\u4e4b\u9593\u4ea4\u63db\u6587\u5b57\u8cc7\u6599\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1aGo\u8a9e\u8a00\u4e2d\u7684\u5b57\u7b26\u96c6\u8f49\u63db\u662f\u4e00\u500b\u91cd\u8981\u7684\u6280\u8853\uff0c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u5c07\u5b57\u7b26\u96c6\u5f9e\u4e00\u7a2e\u8a9e\u8a00\u8f49\u63db\u5230\u53e6\u4e00\u7a2e\u8a9e\u8a00\uff0c\u4ee5\u6eff\u8db3\u4e0d\u540c\u7684\u61c9\u7528\u9700\u6c42\u3002\u672c\u6587\u5c07\u4ecb\u7d39Go\u8a9e\u8a00\u4e2d\u7684\u5b57\u7b26\u96c6\u8f49\u63db\u65b9\u6cd5\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u5011\u4f86\u5be6\u73fe\u8f49\u63db\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[171,172],"tags":[169,170],"class_list":["post-3730","post","type-post","status-publish","format-standard","hentry","category-go","category-golang","tag-go","tag-golang"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-Ya","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=3730"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3730\/revisions"}],"predecessor-version":[{"id":3731,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3730\/revisions\/3731"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}