{"id":5198,"date":"2023-01-05T12:11:05","date_gmt":"2023-01-05T04:11:05","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5198"},"modified":"2023-01-05T12:11:05","modified_gmt":"2023-01-05T04:11:05","slug":"%e4%ba%86%e8%a7%a3typescript%e5%ad%97%e4%b8%b2%e6%b1%82%e6%89%80%e6%9c%89%e5%ad%90%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%bd%8d%e7%bd%ae%e7%9a%84getallsubstringindices%e5%87%bd%e6%95%b8","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%ba%86%e8%a7%a3typescript%e5%ad%97%e4%b8%b2%e6%b1%82%e6%89%80%e6%9c%89%e5%ad%90%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%bd%8d%e7%bd%ae%e7%9a%84getallsubstringindices%e5%87%bd%e6%95%b8\/","title":{"rendered":"\u4e86\u89e3TypeScript\u5b57\u4e32\u6c42\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u4f4d\u7f6e\u7684getAllSubstringIndices\u51fd\u6578"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, \u5b57\u4e32, \u6c42\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u4f4d\u7f6e, getAllSubstringIndices\"><\/p>\n<h1>\u4f7f\u7528 TypeScript \u5b57\u4e32\u7684\u6c42\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u4f4d\u7f6e(getAllSubstringIndices)<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e\u5f37\u578b\u5225\u7684 JavaScript \u8a9e\u8a00\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u958b\u767c\u51fa\u53ef\u9760\u7684\u7a0b\u5f0f\u78bc\u3002\u5728 TypeScript \u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528 <code>getAllSubstringIndices<\/code> \u4f86\u6c42\u53d6\u5b57\u4e32\u4e2d\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u5728 TypeScript \u4e2d\uff0c<code>getAllSubstringIndices<\/code> \u662f\u4e00\u500b\u975e\u5e38\u6709\u7528\u7684\u51fd\u5f0f\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u6c42\u53d6\u5b57\u4e32\u4e2d\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\u3002\u5b83\u7684\u4f7f\u7528\u65b9\u6cd5\u5f88\u7c21\u55ae\uff0c\u53ea\u9700\u8981\u50b3\u5165\u5169\u500b\u53c3\u6578\uff1a\u5b57\u4e32\u548c\u5b50\u5b57\u7b26\u4e32\uff0c\u5c31\u53ef\u4ee5\u5f97\u5230\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u8209\u500b\u4f8b\u5b50\u4f86\u8aaa\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u5b57\u4e32 <code>'Hello World'<\/code>\uff0c\u6211\u5011\u60f3\u8981\u6c42\u53d6\u5b57\u4e32\u4e2d\u6240\u6709 <code>'o'<\/code> \u7684\u4f4d\u7f6e\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 <code>getAllSubstringIndices<\/code> \u4f86\u5be6\u73fe\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet str = 'Hello World';\nlet indices = getAllSubstringIndices(str, 'o');\nconsole.log(indices); \/\/ [4, 7]\n<\/pre>\n<p>\u5f9e\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u53ef\u4ee5\u770b\u51fa\uff0c<code>getAllSubstringIndices<\/code> \u51fd\u5f0f\u6703\u8fd4\u56de\u4e00\u500b\u9663\u5217\uff0c\u9663\u5217\u4e2d\u5305\u542b\u4e86\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u9664\u4e86\u6c42\u53d6\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\u4e4b\u5916\uff0c<code>getAllSubstringIndices<\/code> \u9084\u53ef\u4ee5\u7528\u4f86\u6c42\u53d6\u5b57\u4e32\u4e2d\u6240\u6709\u6307\u5b9a\u5b57\u5143\u7684\u4f4d\u7f6e\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet str = 'Hello World';\nlet indices = getAllSubstringIndices(str, 'l');\nconsole.log(indices); \/\/ [2, 3, 9]\n<\/pre>\n<p>\u53e6\u5916\uff0c<code>getAllSubstringIndices<\/code> \u9084\u53ef\u4ee5\u7528\u4f86\u6c42\u53d6\u5b57\u4e32\u4e2d\u6240\u6709\u6307\u5b9a\u5b57\u4e32\u7684\u4f4d\u7f6e\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet str = 'Hello World';\nlet indices = getAllSubstringIndices(str, 'llo');\nconsole.log(indices); \/\/ [2]\n<\/pre>\n<p>\u7e3d\u4e4b\uff0c<code>getAllSubstringIndices<\/code> \u662f\u4e00\u500b\u975e\u5e38\u6709\u7528\u7684\u51fd\u5f0f\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u6c42\u53d6\u5b57\u4e32\u4e2d\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u5927\u5927\u7c21\u5316\u958b\u767c\u8005\u7684\u5de5\u4f5c\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86 TypeScript \u4e2d\u7684 <code>getAllSubstringIndices<\/code> \u51fd\u5f0f\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u6c42\u53d6\u5b57\u4e32\u4e2d\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u5927\u5927\u7c21\u5316\u958b\u767c\u8005\u7684\u5de5\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:TypeScript\u63d0\u4f9b\u4e86\u4e00\u500bgetAllSubstringIndices\u51fd\u6578\uff0c\u53ef\u4ee5\u7528\u4f86\u6c42\u51fa\u5b57\u4e32\u4e2d\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\uff0c\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528\u9019\u500b\u51fd\u6578\uff0c\u4ee5\u53ca\u5b83\u7684\u512a\u9ede\u548c\u7f3a\u9ede\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[187],"tags":[186],"class_list":["post-5198","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1lQ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5198"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5198\/revisions"}],"predecessor-version":[{"id":5199,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5198\/revisions\/5199"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}