{"id":42781,"date":"2024-12-01T12:28:22","date_gmt":"2024-12-01T04:28:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/42781\/"},"modified":"2024-12-01T12:28:22","modified_gmt":"2024-12-01T04:28:22","slug":"%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e7%9a%84%e7%a9%ba%e6%a0%bc%e6%9b%bf%e6%8d%a2%e4%b8%ba-%e3%80%82%e5%90%8c%e6%97%b6%e4%bd%bf%e7%94%a8-fmt-scan-%e8%bf%9b%e8%a1%8c%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/42781\/","title":{"rendered":"\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\u66ff\u6362\u4e3a\u201c-\u201d\u3002\u540c\u65f6\u4f7f\u7528 fmt.Scan \u8fdb\u884c\u7528\u6237\u8f93\u5165\u3002 \uff08\u6208\u5170\uff09"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\u66ff\u6362\u4e3a\u201c-\u201d\u3002\u540c\u65f6\u4f7f\u7528 fmt.Scan \u8fdb\u884c\u7528\u6237\u8f93\u5165\u3002 \uff08\u6208\u5170\uff09<\/span><\/p>\n<h1>\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\u66ff\u6362\u4e3a\u201c-\u201d\u3002\u540c\u65f6\u4f7f\u7528 fmt.Scan \u8fdb\u884c\u7528\u6237\u8f93\u5165\u3002 \uff08\u6208\u5170\uff09<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-25 23:06:37<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u7c73\u4e91\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\u66ff\u6362\u4e3a\u201c-\u201d\u3002\u540c\u65f6\u4f7f\u7528 fmt.Scan \u8fdb\u884c\u7528\u6237\u8f93\u5165\u3002 \uff08\u6208\u5170\uff09\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p><em>\uff08\u514d\u8d23\u58f0\u660e\uff1a\u6211\u5728 stack overflow \u4e0a\u53d1\u8868\u7684\u7b2c\u4e00\u7bc7\u6587\u7ae0\uff0c\u5bf9 go \u548c\u4e00\u822c\u7f16\u7801\u4e5f\u975e\u5e38\u964c\u751f\u3002\u5982\u679c\u8fd9\u4e2a\u95ee\u9898\u7f3a\u4e4f\u5177\u4f53\u8981\u6c42\uff0c\u6211\u6df1\u8868\u6b49\u610f\u3002\u6240\u4ee5\uff0c\u5982\u679c\u9700\u8981\uff0c\u8bf7\u544a\u8bc9\u6211\u53ef\u4ee5\u66f4\u6539\u54ea\u4e9b\u5185\u5bb9\uff09\u3002 <\/em><\/p>\n<p>\u9996\u5148\uff0c\u63cf\u8ff0\u6211\u60f3\u8981\u5b9e\u73b0\u7684\u76ee\u6807\uff1a<\/p>\n<p>\u6211\u6b63\u5728\u5c1d\u8bd5\u4e3a footpatrol.com \u521b\u5efa\u4e00\u4e2a url \u751f\u6210\u5668\u3002\u8be5\u7a0b\u5e8f\u5c06\u9700\u8981\u4e00\u4e9b\u7528\u6237\u8f93\u5165\uff0c\u4f8b\u5982\u4ea7\u54c1\u540d\u79f0\u548c\u4ea7\u54c1\u4ee3\u7801 (sku) \u7684\u6570\u5b57\u90e8\u5206\u3002\u7136\u540e\u5b83\u5c06\u8fd4\u56de\u4e00\u4e2a\u76f4\u63a5\u8f6c\u5230\u8f93\u5165\u7684\u4ea7\u54c1\u7684 url\u3002 <\/p>\n<p>\u6211\u9047\u5230\u7684\u95ee\u9898\u662f\u201cproductname\u201d\u53d8\u91cf\uff08\u4e0b\u9762\u5c06\u63d0\u4f9b\u4ee3\u7801\uff09\u3002\u9700\u8981\u8fd4\u56de\u4ea7\u54c1\u540d\u79f0\uff0c\u5982\u201c\u989c\u8272-\u54c1\u724c-\u578b\u53f7\u7b49\u201d\u3002\u4f46\u662f\uff0c\u6211\u7684\u7a0b\u5e8f\u8fd8\u6ca1\u6709\u8fd9\u6837\u505a\u3002\u6211\u5c1d\u8bd5\u8fc7\u4f7f\u7528 replace() \u51fd\u6570\uff0c\u4f46\u6ca1\u6709\u5f97\u5230\u6240\u9700\u7684\u7ed3\u679c\u3002\u4e8b\u5b9e\u4e0a\uff0c\u6211\u6ca1\u6709\u5f97\u5230\u4efb\u4f55\u7ed3\u679c\uff0c\u5b83\u53ea\u662f\u8fd4\u56de\u6211\u8f93\u5165\u7684\u7b2c\u4e00\u4e2a\u5355\u8bcd\u3002 <\/p>\n<p>\u6211\u7684\u95ee\u9898\u662f\uff0c\u5982\u4f55\u7528\u201c-\u201d\u66ff\u6362\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\u3002 \u6211\u5c1d\u8bd5\u8fc7\u7684\u5177\u4f53\u4ee3\u7801\uff1a<\/p>\n<p><code>newstr := strings.replace(str, \" \", \"-\", -1)<\/code>\u3002\u5e0c\u671b\u4e0b\u9762\u7684\u4ee3\u7801\u66f4\u6709\u610f\u4e49\u3002 \u6b64\u5916\uff0c\u5b83\u53ea\u8fd4\u56de\u6211\u8f93\u5165\u7684\u7b2c\u4e00\u4e2a\u5355\u8bcd\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6211\u8f93\u5165\u201cwhite nike air force 1\u201d\uff0c\u5b83\u5c06\u8fd4\u56de\u201cwhite\u201d\u3002\u8bf7\u53c2\u9605\u4e0b\u9762\u7684\u4ee3\u7801\uff0c\u5982\u679c\u6211\u80fd\u5f97\u5230\u4efb\u4f55\u5e2e\u52a9\uff0c\u6211\u5c06\u4e0d\u80dc\u611f\u6fc0\u3002 <\/p>\n<p><strong>\u4e0d\u8d77\u4f5c\u7528\u7684\u4ee3\u7801\u548c\u4e0b\u9762\u7684\u5de5\u4f5c\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n\n)\n\nvar skunumber int\nvar productname []string\n\nfunc main() {\n    fmt.println(`please note: a footpatrol product url requires the \"colour\" followed by the name of product. each word is seperated by a hyphen.`)\n\n    fmt.print(\"enter the product name: \")\n    str, err := fmt.scanln(&amp;productname)\n    if err != nil {\n        fmt.println(err)\n    }\n\n    newstr := strings.replace(string(str), \" \", \"-\", -1)\n    fmt.scanln(&amp;newstr)\n\n    fmt.print(\"enter the sku number: \")\n    fmt.scanln(&amp;skunumber)\n\n    fmt.print(\"https:\/\/www.footpatrol.com\/product\/\", newstr, \"\/\", skunumber, \"_footpatrolcom\/\\n\")\n\n} \n<\/pre>\n<p><strong>\u4ee3\u7801\u53ef\u4ee5\u5de5\u4f5c\uff0c\u4f46\u9700\u8981\u8f93\u5165\u51c6\u786e\u7684 url<\/strong><\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n)\n\nvar skuNumber int\nvar productName string\n\nfunc main() {\n    fmt.Println(`PLEASE NOTE: A Footpatrol product URL requires the \"colour\" followed by the name of product. Each word is seperated by a hyphen.`)\n\n    fmt.Print(\"Enter the product name: \")\n    fmt.Scan(&amp;productName)\n\n    fmt.Print(\"Enter the SKU number: \")\n    fmt.Scanln(&amp;skuNumber)\n\n    fmt.Print(\"https:\/\/www.footpatrol.com\/product\/\", productName, \"\/\", skuNumber, \"_footpatrolcom\/\\n\")\n\n}\n\nOutput: \ngo run .\\main.go\nPLEASE NOTE: A Footpatrol product URL requires the \"colour\" followed by the name of product. Each word is seperated by a hyphen.\nEnter the product name: red-nike-zoom-spiridon-cage-2\nEnter the SKU number: 341503\nhttps:\/\/www.footpatrol.com\/product\/red-nike-zoom-spiridon-cage-2\/341503_footpatrolcom\/\n<\/pre>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>1., \u60a8\u5e94\u8be5\u4f7f\u7528 <code>strings.replaceall<\/code> \u800c\u4e0d\u662f <code>strings.replace<\/code>\u3002<br \/> 2.\uff0c\u5728\u60a8\u7684\u5de5\u4f5c\u793a\u4f8b\u4e2d\uff0c\u53ea\u9700\u5728 <code>fmt.scan()<\/code> \u4e4b\u540e\u6dfb\u52a0\u4ee5\u4e0b\u884c\u3002<\/p>\n<pre>...\nfmt.Scan(&amp;productName)\nproductName = strings.ReplaceAll(productName, \" \", \"-\")\n...<\/pre>\n<p>\u8fd9\u5c06\u66ff\u6362\u60a8\u8bfb\u53d6\u4ea7\u54c1\u540d\u79f0\u540e\u51fa\u73b0\u7684\u6240\u6709\u7a7a\u683c\u3002<\/p>\n<p>\u5e0c\u671b\u8fd9\u4f1a\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\u66ff\u6362\u4e3a\u201c-\u201d\u3002\u540c\u65f6\u4f7f\u7528 fmt.Scan \u8fdb\u884c\u7528\u6237\u8f93\u5165\u3002 \uff08\u6208\u5170\uff09\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\u66ff\u6362\u4e3a\u201c-\u201d\u3002\u540c\u65f6\u4f7f\u7528 fmt.Scan \u8fdb\u884c\u7528\u6237\u8f93\u5165\u3002 \uff08\u6208\u5170\uff09 \u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\u66ff\u6362\u4e3a\u201c-\u201d\u3002\u540c\u65f6\u4f7f\u7528 fmt.Scan \u8fdb\u884c\u7528\u6237\u8f93\u5165\u3002 \uff08\u6208\u5170\uff09 \u6765\u6e90\uff1astackoverflow 2024-04-25 23:06:37 0\u6d4f\u89c8 \u6536\u85cf \u7c73\u4e91\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u300a\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\u66ff\u6362\u4e3a\u201c-\u201d\u3002\u540c\u65f6\u4f7f\u7528 fmt.Scan \u8fdb\u884c\u7528\u6237\u8f93\u5165\u3002 \uff08\u6208\u5170\uff09\u300b\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60Golang\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01 \u95ee\u9898\u5185\u5bb9 \uff08\u514d\u8d23\u58f0\u660e\uff1a\u6211\u5728 stack overflow \u4e0a\u53d1\u8868\u7684\u7b2c\u4e00\u7bc7\u6587\u7ae0\uff0c\u5bf9 go \u548c\u4e00\u822c\u7f16\u7801\u4e5f\u975e\u5e38\u964c\u751f\u3002\u5982\u679c\u8fd9\u4e2a\u95ee\u9898\u7f3a\u4e4f\u5177\u4f53\u8981\u6c42\uff0c\u6211\u6df1\u8868\u6b49\u610f\u3002\u6240\u4ee5\uff0c\u5982\u679c\u9700\u8981\uff0c\u8bf7\u544a\u8bc9\u6211\u53ef\u4ee5\u66f4\u6539\u54ea\u4e9b\u5185\u5bb9\uff09\u3002 \u9996\u5148\uff0c\u63cf\u8ff0\u6211\u60f3\u8981\u5b9e\u73b0\u7684\u76ee\u6807\uff1a \u6211\u6b63\u5728\u5c1d\u8bd5\u4e3a footpatrol.com \u521b\u5efa\u4e00\u4e2a url \u751f\u6210\u5668\u3002\u8be5\u7a0b\u5e8f\u5c06\u9700\u8981\u4e00\u4e9b\u7528\u6237\u8f93\u5165\uff0c\u4f8b\u5982\u4ea7\u54c1\u540d\u79f0\u548c\u4ea7\u54c1\u4ee3\u7801 (sku) \u7684\u6570\u5b57\u90e8\u5206\u3002\u7136\u540e\u5b83\u5c06\u8fd4\u56de\u4e00\u4e2a\u76f4\u63a5\u8f6c\u5230\u8f93\u5165\u7684\u4ea7\u54c1\u7684 url\u3002 \u6211\u9047\u5230\u7684\u95ee\u9898\u662f\u201cproductname\u201d\u53d8\u91cf\uff08\u4e0b\u9762\u5c06\u63d0\u4f9b\u4ee3\u7801\uff09\u3002\u9700\u8981\u8fd4\u56de\u4ea7\u54c1\u540d\u79f0\uff0c\u5982\u201c\u989c\u8272-\u54c1\u724c-\u578b\u53f7\u7b49\u201d\u3002\u4f46\u662f\uff0c\u6211\u7684\u7a0b\u5e8f\u8fd8\u6ca1\u6709\u8fd9\u6837\u505a\u3002\u6211\u5c1d\u8bd5\u8fc7\u4f7f\u7528 replace() \u51fd\u6570\uff0c\u4f46\u6ca1\u6709\u5f97\u5230\u6240\u9700\u7684\u7ed3\u679c\u3002\u4e8b\u5b9e\u4e0a\uff0c\u6211\u6ca1\u6709\u5f97\u5230\u4efb\u4f55\u7ed3\u679c\uff0c\u5b83\u53ea\u662f\u8fd4\u56de\u6211\u8f93\u5165\u7684\u7b2c\u4e00\u4e2a\u5355\u8bcd\u3002 \u6211\u7684\u95ee\u9898\u662f\uff0c\u5982\u4f55\u7528\u201c-\u201d\u66ff\u6362\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\u3002 \u6211\u5c1d\u8bd5\u8fc7\u7684\u5177\u4f53\u4ee3\u7801\uff1a newstr := strings.replace(str, &#8221; &#8220;, &#8220;-&#8220;, -1)\u3002\u5e0c\u671b\u4e0b\u9762\u7684\u4ee3\u7801\u66f4\u6709\u610f\u4e49\u3002 \u6b64\u5916\uff0c\u5b83\u53ea\u8fd4\u56de\u6211\u8f93\u5165\u7684\u7b2c\u4e00\u4e2a\u5355\u8bcd\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6211\u8f93\u5165\u201cwhite nike air force 1\u201d\uff0c\u5b83\u5c06\u8fd4\u56de\u201cwhite\u201d\u3002\u8bf7\u53c2\u9605\u4e0b\u9762\u7684\u4ee3\u7801\uff0c\u5982\u679c\u6211\u80fd\u5f97\u5230\u4efb\u4f55\u5e2e\u52a9\uff0c\u6211\u5c06\u4e0d\u80dc\u611f\u6fc0\u3002 [&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-42781","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42781","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=42781"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42781\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=42781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=42781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=42781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}