{"id":1499,"date":"2023-06-28T09:43:56","date_gmt":"2023-06-28T01:43:56","guid":{"rendered":"http:\/\/www.plm.cn\/?p=1499"},"modified":"2023-07-09T14:33:11","modified_gmt":"2023-07-09T06:33:11","slug":"%e4%bd%8e%e4%bb%a3%e7%a0%81%e7%9a%84lua%e5%87%bd%e6%95%b0split%ef%bc%88%e5%88%86%e5%89%b2%e5%ad%97%e7%ac%a6%e4%b8%b2%ef%bc%89","status":"publish","type":"post","link":"http:\/\/www.plm.cn\/1499\/","title":{"rendered":"\u4f4e\u4ee3\u7801\u7684lua\u51fd\u6570split\uff08\u5206\u5272\u5b57\u7b26\u4e32\uff09"},"content":{"rendered":"

\u529f\u80fd\u8bf4\u660e\uff1a
\n\u6709\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5982 “2023-10-02”, \u9700\u8981\u628a\u5b83\u5206\u5272\u4e3a “2023” “10” “02” \u8fd9\u6837\u4e09\u4e2a\u5b57\u7b26\u4e32<\/p><\/blockquote>\n

function<\/span> split<\/span>(<\/span> strItem,<\/span> separator )<\/span>\r\n<\/pre>\n

\u8f93\u5165\u53c2\u6570<\/p><\/blockquote>\n

    \n
  • strItem<\/strong>\u00a0\u9700\u8981\u5206\u5272\u7684\u5b57\u7b26\u4e32<\/li>\n
  • separator<\/strong>\u00a0\u5206\u5272\u7b26\u53f7\uff0c\u5982 “-“<\/li>\n<\/ul>\n

    \u8f93\u51fa\u53c2\u6570<\/p><\/blockquote>\n

      \n
    • segment<\/strong>\u00a0\u4e00\u4e2ajson\u6570\u7ec4\u5bf9\u8c61 {“2023″,”10″,”02”}<\/li>\n<\/ul>\n
      \n

      Example<\/p>\n<\/div>\n

      \u8bf4\u660e\uff1a\u6709\u4e00\u4e2a\u6d47\u6ce8\u6279\u6b21\u53f7\uff0c\u5982\uff1a”TY230201-MG02-T2-254″, \u9700\u8981\u83b7\u53d6\u5176\u4e2d MG02 \u8fd9\u4e2a\u4ea7\u54c1\u68c0\u7d22\u53f7<\/p>\n

          -- \u4ece\u6d47\u94f8\u6279\u6b21\u53f7\u4e2d\u83b7\u53d6\u68c0\u7d22\u53f7<\/span>\r\n    local<\/span> strCBCode =<\/span> \"TY230201-MG02-T2-254\"<\/span>\r\n    local<\/span> seg =<\/span> {<\/span>}<\/span>\r\n    local<\/span> strIndexNo        -- \u68c0\u7d22\u53f7<\/span>\r\n\r\n    seg =<\/span> split<\/span>(<\/span> strCBCode,<\/span> \"-\"<\/span> )<\/span>\r\n    local<\/span> nCount =<\/span> #<\/span>seg\r\n    -- \u5982\u679c\u7f16\u7801\u4e0d\u662f4\u6bb5\u7801\u8bf4\u660e\u4e0d\u7b26\u5408\u89c4\u8303<\/span>\r\n    if<\/span> (<\/span> nCount ~=<\/span> 4<\/span> )<\/span> then<\/span>\r\n        mobox.<\/span>error<\/span>(<\/span> strLuaDEID,<\/span> \"\u6d47\u94f8\u6279\u6b21\u53f7\u683c\u5f0f\u4e0d\u5408\u6cd5!\"<\/span> )<\/span>\r\n        return<\/span>    \r\n    end<\/span>\r\n    strIndexNo =<\/span> seg[<\/span>4<\/span>]<\/span>    -- \u83b7\u53d6\u68c0\u7d22\u53f7<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"

      \u529f\u80fd\u8bf4\u660e\uff1a \u6709\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5982 “2023-10-02”, \u9700\u8981\u628a\u5b83\u5206\u5272\u4e3a &#8220 […]<\/p>\n","protected":false},"author":1,"featured_media":1496,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,5,1],"tags":[13],"class_list":["post-1499","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-eckf","category-plmcenter","category-didaima","tag-shouche"],"_links":{"self":[{"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/posts\/1499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/comments?post=1499"}],"version-history":[{"count":1,"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/posts\/1499\/revisions"}],"predecessor-version":[{"id":1500,"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/posts\/1499\/revisions\/1500"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/media\/1496"}],"wp:attachment":[{"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/media?parent=1499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/categories?post=1499"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.plm.cn\/wp-json\/wp\/v2\/tags?post=1499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}