{"id":42163,"date":"2024-12-01T13:44:04","date_gmt":"2024-12-01T05:44:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/42163\/"},"modified":"2024-12-01T13:44:04","modified_gmt":"2024-12-01T05:44:04","slug":"%e9%80%9a%e8%bf%87%e5%88%a0%e9%99%a4-golang-%e4%b8%ad%e7%9a%84%e5%ad%90%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%88%86%e6%88%90%e4%b8%a4%e9%83%a8%e5%88%86","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/42163\/","title":{"rendered":"\u901a\u8fc7\u5220\u9664 golang \u4e2d\u7684\u5b50\u5b57\u7b26\u4e32\u5c06\u5b57\u7b26\u4e32\u5206\u6210\u4e24\u90e8\u5206"},"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>\u901a\u8fc7\u5220\u9664 golang \u4e2d\u7684\u5b50\u5b57\u7b26\u4e32\u5c06\u5b57\u7b26\u4e32\u5206\u6210\u4e24\u90e8\u5206<\/span><\/p>\n<h1>\u901a\u8fc7\u5220\u9664 golang \u4e2d\u7684\u5b50\u5b57\u7b26\u4e32\u5c06\u5b57\u7b26\u4e32\u5206\u6210\u4e24\u90e8\u5206<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-22 20:36:39<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300a\u901a\u8fc7\u5220\u9664 golang \u4e2d\u7684\u5b50\u5b57\u7b26\u4e32\u5c06\u5b57\u7b26\u4e32\u5206\u6210\u4e24\u90e8\u5206\u300b\uff0c\u8986\u76d6\u4e86Golang\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u5c1d\u8bd5\u89e3\u6790\u770b\u8d77\u6765\u50cf\u8fd9\u6837\u7684\u5b57\u7b26\u4e32\uff1a<\/p>\n<p><code>abc************xyz<\/code><\/p>\n<p>\u653e\u5165\u201cabc\u201d\u548c\u201cxyz\u201d\u7684\u5207\u7247\uff08\u62162\u4e2a\u53d8\u91cf\uff09\u4e2d\uff0c\u5220\u9664\u6240\u6709\u661f\u53f7\u3002<\/p>\n<p><code>*<\/code> \u7684\u6570\u91cf\u53ef\u4ee5\u662f\u53ef\u53d8\u7684\uff0c\u6bcf\u8fb9\u7684\u5b57\u6bcd\u4e5f\u53ef\u4ee5\u662f\u53ef\u53d8\u7684\uff0c\u56e0\u6b64\u5b83\u4e0d\u4e00\u5b9a\u662f\u56fa\u5b9a\u957f\u5ea6\u3002\u6211\u60f3\u77e5\u9053 go \u662f\u5426\u6709\u4e00\u4e2a\u5f88\u597d\u7684\u65b9\u6cd5\u6765\u4f7f\u7528 strings \u5305\u6765\u505a\u5230\u8fd9\u4e00\u70b9\uff1f<\/p>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u4f7f\u7528 \uff0c\u5176\u4e2d <code>*<\/code> \u662f\u5b57\u6bb5\u5206\u9694\u7b26\u3002<\/p>\n<pre>s := \"abc***********xyz\"\nz := strings.FieldsFunc(s, func(r rune) bool { return r == '*' })\nfmt.Println(len(z), z)  \/\/ prints 2 [abc xyz]<\/pre>\n<p>\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u901a\u8fc7\u5220\u9664 golang \u4e2d\u7684\u5b50\u5b57\u7b26\u4e32\u5c06\u5b57\u7b26\u4e32\u5206\u6210\u4e24\u90e8\u5206 \u901a\u8fc7\u5220\u9664 golang \u4e2d\u7684\u5b50\u5b57\u7b26\u4e32\u5c06\u5b57\u7b26\u4e32\u5206\u6210\u4e24\u90e8\u5206 \u6765\u6e90\uff1astackoverflow 2024-04-22 20:36:39 0\u6d4f\u89c8 \u6536\u85cf \u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300a\u901a\u8fc7\u5220\u9664 golang \u4e2d\u7684\u5b50\u5b57\u7b26\u4e32\u5c06\u5b57\u7b26\u4e32\u5206\u6210\u4e24\u90e8\u5206\u300b\uff0c\u8986\u76d6\u4e86Golang\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002 \u95ee\u9898\u5185\u5bb9 \u6211\u6b63\u5728\u5c1d\u8bd5\u89e3\u6790\u770b\u8d77\u6765\u50cf\u8fd9\u6837\u7684\u5b57\u7b26\u4e32\uff1a abc************xyz \u653e\u5165\u201cabc\u201d\u548c\u201cxyz\u201d\u7684\u5207\u7247\uff08\u62162\u4e2a\u53d8\u91cf\uff09\u4e2d\uff0c\u5220\u9664\u6240\u6709\u661f\u53f7\u3002 * \u7684\u6570\u91cf\u53ef\u4ee5\u662f\u53ef\u53d8\u7684\uff0c\u6bcf\u8fb9\u7684\u5b57\u6bcd\u4e5f\u53ef\u4ee5\u662f\u53ef\u53d8\u7684\uff0c\u56e0\u6b64\u5b83\u4e0d\u4e00\u5b9a\u662f\u56fa\u5b9a\u957f\u5ea6\u3002\u6211\u60f3\u77e5\u9053 go \u662f\u5426\u6709\u4e00\u4e2a\u5f88\u597d\u7684\u65b9\u6cd5\u6765\u4f7f\u7528 strings \u5305\u6765\u505a\u5230\u8fd9\u4e00\u70b9\uff1f \u6b63\u786e\u7b54\u6848 \u4f7f\u7528 \uff0c\u5176\u4e2d * \u662f\u5b57\u6bb5\u5206\u9694\u7b26\u3002 s := &#8220;abc***********xyz&#8221; z := strings.FieldsFunc(s, func(r rune) bool { return r == &#8216;*&#8217; }) fmt.Println(len(z), z) \/\/ prints 2 [&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-42163","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42163","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=42163"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42163\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=42163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=42163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=42163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}