{"id":38779,"date":"2024-11-26T17:13:57","date_gmt":"2024-11-26T09:13:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38779\/"},"modified":"2024-11-26T17:13:57","modified_gmt":"2024-11-26T09:13:57","slug":"java%e4%b8%ad%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e6%8b%86%e5%88%86%e5%ad%97%e7%ac%a6%e4%b8%b2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38779\/","title":{"rendered":"java\u4e2d\u6570\u7ec4\u600e\u4e48\u62c6\u5206\u5b57\u7b26\u4e32"},"content":{"rendered":"<blockquote><p>\n  string.split() \u65b9\u6cd5\u4f7f\u7528\u6307\u5b9a\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u62c6\u5206\u5b57\u7b26\u4e32\uff0c\u751f\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u3002\u4f7f\u7528\u65b9\u5f0f\uff1astring[] parts = string.split(regex)\uff0c\u5176\u4e2d string \u4e3a\u8981\u62c6\u5206\u7684\u5b57\u7b26\u4e32\uff0cregex \u4e3a\u6307\u5b9a\u62c6\u5206\u89c4\u5219\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111506190974180.jpg\" class=\"aligncenter\" title=\"java\u4e2d\u6570\u7ec4\u600e\u4e48\u62c6\u5206\u5b57\u7b26\u4e32\u63d2\u56fe\" alt=\"java\u4e2d\u6570\u7ec4\u600e\u4e48\u62c6\u5206\u5b57\u7b26\u4e32\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u4f7f\u7528 String.split() \u65b9\u6cd5\u62c6\u5206\u5b57\u7b26\u4e32<\/strong><\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong><br \/>\u4f7f\u7528 String.split() \u65b9\u6cd5\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u6839\u636e\u6307\u5b9a\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u62c6\u5206\u6210\u4e00\u4e2a\u3002<\/p>\n<p><strong>\u4f7f\u7528\u8bf4\u660e\uff1a<\/strong><\/p>\n<pre>String[] parts = string.split(regex);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>string \u8981\u62c6\u5206\u7684\u5b57\u7b26\u4e32\u3002<\/li>\n<li>regex \u6307\u5b9a\u62c6\u5206\u89c4\u5219\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3002<\/li>\n<\/ul>\n<p><strong>\u5c55\u5f00\uff1a<\/strong><\/p>\n<p><strong>\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a<\/strong><br \/>\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u7528\u4e8e\u6307\u5b9a\u5339\u914d\u6a21\u5f0f\u3002\u5e38\u7528\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6709\uff1a<\/p>\n<ul>\n<li>.: \u5339\u914d\u4efb\u4f55\u5b57\u7b26\u3002<\/li>\n<li>*: \u5339\u914d\u524d\u4e00\u4e2a\u5b57\u7b26 0 \u6b21\u6216\u591a\u6b21\u3002<\/li>\n<li>+: \u5339\u914d\u524d\u4e00\u4e2a\u5b57\u7b26 1 \u6b21\u6216\u591a\u6b21\u3002<\/li>\n<li>?: \u5339\u914d\u524d\u4e00\u4e2a\u5b57\u7b26 0 \u6b21\u6216 1 \u6b21\u3002<\/li>\n<li>|: \u5339\u914d\u4e24\u79cd\u6a21\u5f0f\u4e2d\u7684\u4e00\u79cd\u3002<\/li>\n<li>d: \u5339\u914d\u6570\u5b57\u5b57\u7b26\u3002<\/li>\n<li>w: \u5339\u914d\u5355\u8bcd\u5b57\u7b26\uff08\u5b57\u6bcd\u3001\u6570\u5b57\u6216\u4e0b\u5212\u7ebf\uff09\u3002<\/li>\n<li>s: \u5339\u914d\u7a7a\u767d\u5b57\u7b26\uff08\u7a7a\u683c\u3001\u5236\u8868\u7b26\u3001\u6362\u884c\u7b26\u7b49\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>\/\/ \u6839\u636e\u7a7a\u683c\u62c6\u5206\u5b57\u7b26\u4e32\nString[] parts = \"Hello world\".split(\" \");\n\n\/\/ \u6839\u636e\u9017\u53f7\u62c6\u5206\u5b57\u7b26\u4e32\nString[] parts = \"name,age,gender\".split(\",\");\n\n\/\/ \u6839\u636e\u6570\u5b57\u5b57\u7b26\u62c6\u5206\u5b57\u7b26\u4e32\nString[] parts = \"123-456-789\".split(\"\\d\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u4e0d\u6307\u5b9a\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u5219 split() \u65b9\u6cd5\u5c06\u6839\u636e\u7a7a\u683c\u62c6\u5206\u5b57\u7b26\u4e32\u3002<\/li>\n<li>\u62c6\u5206\u7ed3\u679c\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd\u4ee3\u8868\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u6bb5\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u4e2d\u6570\u7ec4\u600e\u4e48\u62c6\u5206\u5b57\u7b26\u4e32\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>string.split() \u65b9\u6cd5\u4f7f\u7528\u6307\u5b9a\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u62c6\u5206\u5b57\u7b26\u4e32\uff0c\u751f\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u3002\u4f7f\u7528\u65b9\u5f0f\uff1astring[] parts = string.split(regex)\uff0c\u5176\u4e2d string \u4e3a\u8981\u62c6\u5206\u7684\u5b57\u7b26\u4e32\uff0cregex \u4e3a\u6307\u5b9a\u62c6\u5206\u89c4\u5219\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3002 Java \u4e2d\u4f7f\u7528 String.split() \u65b9\u6cd5\u62c6\u5206\u5b57\u7b26\u4e32 \u56de\u7b54\uff1a\u4f7f\u7528 String.split() \u65b9\u6cd5\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u6839\u636e\u6307\u5b9a\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u62c6\u5206\u6210\u4e00\u4e2a\u3002 \u4f7f\u7528\u8bf4\u660e\uff1a String[] parts = string.split(regex); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b string \u8981\u62c6\u5206\u7684\u5b57\u7b26\u4e32\u3002 regex \u6307\u5b9a\u62c6\u5206\u89c4\u5219\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3002 \u5c55\u5f00\uff1a \u6b63\u5219\u8868\u8fbe\u5f0f\uff1a\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u7528\u4e8e\u6307\u5b9a\u5339\u914d\u6a21\u5f0f\u3002\u5e38\u7528\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6709\uff1a .: \u5339\u914d\u4efb\u4f55\u5b57\u7b26\u3002 *: \u5339\u914d\u524d\u4e00\u4e2a\u5b57\u7b26 0 \u6b21\u6216\u591a\u6b21\u3002 +: \u5339\u914d\u524d\u4e00\u4e2a\u5b57\u7b26 1 \u6b21\u6216\u591a\u6b21\u3002 ?: \u5339\u914d\u524d\u4e00\u4e2a\u5b57\u7b26 0 \u6b21\u6216 1 \u6b21\u3002 |: \u5339\u914d\u4e24\u79cd\u6a21\u5f0f\u4e2d\u7684\u4e00\u79cd\u3002 d: \u5339\u914d\u6570\u5b57\u5b57\u7b26\u3002 w: \u5339\u914d\u5355\u8bcd\u5b57\u7b26\uff08\u5b57\u6bcd\u3001\u6570\u5b57\u6216\u4e0b\u5212\u7ebf\uff09\u3002 s: \u5339\u914d\u7a7a\u767d\u5b57\u7b26\uff08\u7a7a\u683c\u3001\u5236\u8868\u7b26\u3001\u6362\u884c\u7b26\u7b49\uff09\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-38779","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38779","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=38779"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38779\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}