{"id":38,"date":"2023-10-05T21:19:32","date_gmt":"2023-10-05T13:19:32","guid":{"rendered":"https:\/\/wp.minicoda.com\/?p=38"},"modified":"2025-01-19T21:25:09","modified_gmt":"2025-01-19T13:25:09","slug":"%e6%a0%bc%e5%bc%8f%e4%b8%b2","status":"publish","type":"post","link":"https:\/\/wp.minicoda.com\/index.php\/%e6%a0%bc%e5%bc%8f%e4%b8%b2\/","title":{"rendered":"\u683c\u5f0f\u4e32\u57fa\u672c\u89c4\u5219"},"content":{"rendered":"\n<p>\u7f16\u7a0b\u8bed\u8a00\u6bd5\u7adf\u662f\u6587\u672c\uff0c\u53ea\u5728ASCII\u7801\u5185\u65e0\u6cd5\u8868\u8fbe\u66f4\u591a\u7684\u542b\u4e49\uff0c\u5982\u679c\u4e0d\u7528\u65b0\u7684\u51fd\u6570\u6216\u8005\u5173\u952e\u5b57\uff0c\u5c31\u9700\u8981\u7528\u201c\u8f6c\u4e49\u201d\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u6765\u4ee3\u8868\u7279\u5b9a\u683c\u5f0f\u4e32\u3002\u8fd9\u5c31\u662f\u683c\u5f0f\u4e32\u7684\u6765\u6e90\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u683c\u5f0f<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C\/ObjC \u8bed\u8a00\u7684\u683c\u5f0f\u4e32\u6bd4\u8f83\u5178\u578b\uff0c\u91c7\u7528%\u7b26\u53f7\u4f5c\u4e3a\u683c\u5f0f\u7c7b\u578b\u524d\u7f00\uff0c\u907f\u514d\u7f16\u8bd1\u5668\u5f53\u505a\u666e\u901a%\u5b57\u7b26\u3002\u6b64\u65b9\u6cd5\u6709\u4e00\u5b9a\u4f18\u52bf\uff0c\u540c\u4e00\u4e2a\u5185\u5b58\u53d8\u91cf\u53ef\u4ee5\u7528\u4e0d\u540c%\u683c\u5f0f\u8868\u8fbe\uff0c\u53ef\u4ee5\u968f\u5fc3\u63a7\u5236\u3002<\/li>\n\n\n\n<li>C++\u9664\u4e86\u7ee7\u627f\u5b83\uff0ciostream\u63d0\u4f9b\u4e86\u65b0\u7684\u8bbe\u5b9a\u6a21\u5f0f\uff0c\u5f62\u5982ios setw\/setprecision\/fixed\u7b49\u5c5e\u6027\uff0c\u5b83\u4f9d\u6258\u8f93\u5165\u8f93\u51fa\u6d41\u5bf9\u8c61\u5c5e\u6027\u3002C++20\u5f15\u5165\u4e86std::format()\u96c6\u6210\u4e86\u683c\u5f0f\u5316\u7684\u4f18\u70b9\uff0c\u9887\u6709C#\u98ce\u683c\uff0c\u4f8b\u5982\uff1a\n<ul class=\"wp-block-list\">\n<li>std::format(\"Age: {}, sex: {}\", 28, 1) \/\/ \u8f93\u51faAge: 28, sex: 1<\/li>\n\n\n\n<li>std::format(\"{1}, {0}, {1}\", 1, 2) \/\/ \u8f93\u51fa2, 1, 2\n<ul class=\"wp-block-list\">\n<li>C++20\u4e5f\u63d0\u4f9b\u4e86\u81ea\u5b9a\u4e49\u7c7b\u578bparse\/format\u65b9\u6cd5std::formatter\u7c7b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>C#\u6539\u8fdb\u4e86C\u8bed\u8a00\u5fc5\u987b\u5199%\u683c\u5f0f\u7b26\u7684\u95ee\u9898\uff0c\u7528{0} {1}\u8868\u8fbe\u4e0d\u540c\u53d8\u91cf\uff0c\u4e5f\u88ab\u79f0\u4e3a\u590d\u5408\u683c\u5f0f\u5316\u3002C# 6.0\u4e4b\u540e\u66f4\u751a\uff0c0\u548c1\u90fd\u4e0d\u7528\u8f93\u5165\uff0c\u5229\u7528\u5b57\u7b26\u4e32\u524d\u6dfb\u52a0$\u5c06\u53d8\u91cf\u653e\u5165{}\u5373\u53ef\u3002\n<ul class=\"wp-block-list\">\n<li>\u6ce8\u610f\uff0c\u5360\u4f4d\u7b26\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\uff0c\u4e5f\u53ef\u4ee5\u591a\u6b21\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Python\u9664\u4e86\u7c7b\u4f3cC\u8bed\u8a00\u7684%\u683c\u5f0f\u4e32\uff0c\u8fd8\u63d0\u4f9b\u5b57\u7b26\u4e32\u7684format\u65b9\u6cd5\uff0cPython 3.6\u4ee5\u4e0a\u8fd8\u63d0\u4f9bf-string\u521b\u5efa\u683c\u5f0f\u4e32\uff0c\u5b83\u548cC#\u7684{}\u5360\u4f4d\u7b26\u7c7b\u4f3c\uff0c\u4f8b\u5982f\"name: {name}, sex: {sex}\".\n<ul class=\"wp-block-list\">\n<li>%\u683c\u5f0f\u4e32\u9700\u8981\u5728\u771f\u5b9e\u53d8\u91cf\u524d\u7edf\u4e00\u52a0%\uff0c\u7a0d\u663e\u7e41\u7410\uff0c\u4f8b\u5982print(\"%d %d\", % (a, b)).<\/li>\n\n\n\n<li>Python 2.6\u5f00\u59cb\u652f\u6301\u5b57\u7b26\u4e32format\u65b9\u6cd5\uff0c\u867d\u7136\u4e5f\u53ef\u4ee5\u5b8c\u6210f-string\u540c\u6837\u7684\u529f\u80fd\uff0c\u4f46\u7a0d\u663e\u7e41\u7410\uff1a<br><a href=\"https:\/\/docs.python.org\/3\/whatsnew\/2.6.html#pep-3101-advanced-string-formatting\">What\u2019s New in Python 2.6<\/a><\/li>\n\n\n\n<li>f-string\u683c\u5f0f\u4e32\u8fd8\u652f\u6301\u63d2\u5165\u51fd\u6570\uff0c\u4f8b\u5982f\"{len(str)}\"\u662fstr\u7684\u957f\u5ea6\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Swift\u4e5f\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u7ea6\u7684\u5b57\u7b26\u4e32\u63d2\u503c\u65b9\u5f0f\uff0c\u5f62\u5982\uff1alet s3 = \"\\(str1) \\(str2)\"<\/li>\n\n\n\n<li>Rust\u4f7f\u7528{}\u683c\u5f0f\u5b9e\u73b0\u5b57\u7b26\u4e32\u63d2\u503c\u3002<\/li>\n\n\n\n<li>Java\u5bf9\u4e8e\u7b80\u7ea6\u683c\u5f0f\u4e32\u7684\u652f\u6301\u6bd4\u8f83\u843d\u540e\uff0cJava 15\u5f00\u59cb\u624d\u652f\u6301formatted\u65b9\u6cd5\uff0c\u4f46\u5176\u65b9\u4fbf\u7a0b\u5ea6\u53ea\u80fd\u548c\u539f\u59cb\u7684C\u8bed\u8a00%\u683c\u5f0f\u4e32\u5c5e\u4e8e\u4e00\u4e2a\u7ea7\u522b\u3002<\/li>\n\n\n\n<li>VB \u683c\u5f0f\u4e32\u7279\u7acb\u72ec\u884c\uff0c\u5229\u7528Format\u51fd\u6570\uff0c\u901a\u8fc7\u4f20\u9012\u4e00\u4e9b\u7279\u522b\u7684\u683c\u5f0f\u5b57\u7b26\u8fbe\u5230\u7279\u5b9a\u663e\u793a\u3002\n<ul class=\"wp-block-list\">\n<li>\u6570\u503c\u7c7b\u578b\uff1a\u4f8b\u5982 0\u4ee3\u8868\u663e\u793a\u5b57\u7b26\u6216\u80050\uff0c#\u4ee3\u8868\u663e\u793a\u5b57\u7b26\u6216\u4e0d\u663e\u793a\uff0c%\u4ee3\u8868\u767e\u5206\u6bd4\u683c\u5f0f\u3002<br>Format(123, \"00000\") \u4f1a\u8f93\u51fa\uff1a\"00123\" (\u5b9e\u9645\u663e\u793a\u53bb\u6389\u4e24\u8fb9\u7684\u5f15\u53f7)<\/li>\n\n\n\n<li>\u5b57\u7b26\u683c\u5f0f\u7c7b\u578b\uff1a\u4f8b\u5982 @\u4ee3\u8868\u663e\u793a\u5b57\u7b26\u6216\u8005\u7a7a\u683c\uff0c&amp;\u4ee3\u8868\u663e\u793a\u5b57\u7b26\u6216\u8005\u4e0d\u663e\u793a\u3002<br>Format(\"xyz\", \"@@@@\") \u4f1a\u5c55\u793a\uff1a\" xyz\" (\u5b9e\u9645\u663e\u793a\u53bb\u6389\u4e24\u8fb9\u7684\u5f15\u53f7)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e0d\u540c\u683c\u5f0f\u7b26<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C\u8bed\u8a00%d\u5bf9\u5e94\u6574\u5f62\uff0c%hd\u548c%ld\u5bf9\u5e94\u77ed\u6574\u5f62\u548c\u957f\u6574\u5f62\u3002\u683c\u5f0f\u4e32\u89e3\u6790\u662f\u5728libc\u5b8c\u6210\u3002\n<ul class=\"wp-block-list\">\n<li>\u4e0d\u80fd\u6709%h\u6216%l\u683c\u5f0f\u4e32\uff0c\u4f1a\u4ea7\u751f\u51b2\u7a81\u3002<\/li>\n\n\n\n<li>VS2019\u7f16\u8bd1C\u4ee3\u7801\u53ea\u6709%h\u683c\u5f0f\u7b26: \u7f16\u8bd1\u8b66\u544a: <code>\u683c\u5f0f\u5b57\u7b26\u4e32\u201c%h\u201d\u672a\u7ec8\u6b62<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u5982\u679c\u65b0\u589e\u683c\u5f0f\u7b26\uff0c\u53ef\u4ee5\u9009\u62e9\u6ca1\u6709\u7528\u8fc7\u7684\u7b26\u53f7\u3002<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u683c\u5f0f\u4e32\u5b89\u5168<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C\u8bed\u8a00\u53ef\u4ee5\u81ea\u7531\u4f7f\u7528\u683c\u5f0f\u5316\uff0c\u4e14printf\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3aconst char *\u4e5f\u53ef\u6709\u7a0b\u5e8f\u5458\u6307\u5b9a\uff0c\u5f62\u5982printf(s)\u6709\u5f88\u5927\u98ce\u9669\u3002\u53ef\u4ee5\u6784\u9020\u5b57\u7b26\u4e32s\u4e2d\u7684\u683c\u5f0f\u7b26\uff0c\u8bef\u5bfc\u7a0b\u5e8f\u53bb\u8bbf\u95ee\u7279\u5b9a\u5185\u5b58\u3002scanf\u540c\u6837\u53ef\u4ee5\u6784\u9020\u5e26\u7279\u5b9a\u683c\u5f0f\uff0c\u4ea7\u751f\u4e00\u4e9b\u6709\u8da3\u6216\u5371\u9669\u7684\u7ed3\u679c\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u7f16\u7a0b\u8bed\u8a00\u6bd5\u7adf\u662f\u6587\u672c\uff0c\u53ea\u5728ASCII\u7801\u5185\u65e0\u6cd5\u8868\u8fbe\u66f4\u591a\u7684\u542b\u4e49\uff0c\u5982\u679c\u4e0d\u7528\u65b0\u7684\u51fd\u6570\u6216\u8005\u5173\u952e\u5b57\uff0c\u5c31\u9700\u8981\u7528\u201c\u8f6c\u4e49\u201d\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u6765\u4ee3\u8868\u7279\u5b9a\u683c\u5f0f\u4e32\u3002\u8fd9\u5c31\u662f\u683c\u5f0f\u4e32\u7684\u6765\u6e90\u3002 \u683c\u5f0f \u4e0d\u540c\u683c\u5f0f\u7b26 \u683c\u5f0f\u4e32\u5b89\u5168<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44,8],"tags":[45,9],"class_list":["post-38","post","type-post","status-publish","format-standard","hentry","category-44","category-8","tag-45","tag-9"],"views":121,"_links":{"self":[{"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/posts\/38","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/comments?post=38"}],"version-history":[{"count":15,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/posts\/38\/revisions"}],"predecessor-version":[{"id":3607,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/posts\/38\/revisions\/3607"}],"wp:attachment":[{"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/media?parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/categories?post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/tags?post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}