{"id":5182,"date":"2023-01-05T12:09:00","date_gmt":"2023-01-05T04:09:00","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5182"},"modified":"2023-01-05T12:09:00","modified_gmt":"2023-01-05T04:09:00","slug":"%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8typescript%e4%b8%ad%e7%9a%84getfirstsubstringindex%e5%87%bd%e6%95%b8","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8typescript%e4%b8%ad%e7%9a%84getfirstsubstringindex%e5%87%bd%e6%95%b8\/","title":{"rendered":"\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528TypeScript\u4e2d\u7684getFirstSubstringIndex\u51fd\u6578"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, \u5b57\u4e32, \u6c42\u9996\u5b50\u5b57\u7b26\u4e32\u4f4d\u7f6e, getFirstSubstringIndex\"><\/p>\n<h1>TypeScript \u5b57\u4e32\u7684\u6c42\u9996\u5b50\u5b57\u7b26\u4e32\u4f4d\u7f6e(getFirstSubstringIndex)<\/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>getFirstSubstringIndex<\/code> \u4f86\u6c42\u51fa\u5b57\u4e32\u4e2d\u9996\u500b\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u4f7f\u7528 <code>getFirstSubstringIndex<\/code> \u4f86\u6c42\u51fa\u5b57\u4e32\u4e2d\u9996\u500b\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u64cd\u4f5c\u5b57\u4e32\uff0c\u4f8b\u5982\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u64f7\u53d6\u5b57\u4e32\u4e2d\u7684\u67d0\u500b\u5b50\u5b57\u7b26\u4e32\uff0c\u6216\u662f\u66f4\u5bb9\u6613\u5730\u66ff\u63db\u5b57\u4e32\u4e2d\u7684\u67d0\u500b\u5b50\u5b57\u7b26\u4e32\u3002<\/p>\n<h2>\u4f7f\u7528 <code>getFirstSubstringIndex<\/code> \u6c42\u51fa\u5b57\u4e32\u4e2d\u9996\u500b\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e<\/h2>\n<p>\u4f7f\u7528 <code>getFirstSubstringIndex<\/code> \u4f86\u6c42\u51fa\u5b57\u4e32\u4e2d\u9996\u500b\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet str = \"Hello World\";\nlet index = str.getFirstSubstringIndex(\"World\");\nconsole.log(index); \/\/ 6\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u5ba3\u544a\u4e86\u4e00\u500b\u5b57\u4e32 <code>str<\/code>\uff0c\u4e26\u4e14\u4f7f\u7528 <code>getFirstSubstringIndex<\/code> \u4f86\u6c42\u51fa\u5b57\u4e32\u4e2d\u9996\u500b\u5b50\u5b57\u7b26\u4e32 <code>World<\/code> \u7684\u4f4d\u7f6e\uff0c\u6700\u5f8c\u5c07\u7d50\u679c\u8f38\u51fa\u5230\u63a7\u5236\u53f0\uff0c\u7d50\u679c\u70ba <code>6<\/code>\uff0c\u8868\u793a <code>World<\/code> \u5728 <code>str<\/code> \u4e2d\u7684\u4f4d\u7f6e\u70ba\u7b2c 6 \u500b\u5b57\u5143\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u64f7\u53d6\u5b57\u4e32\u4e2d\u7684\u67d0\u500b\u5b50\u5b57\u7b26\u4e32<\/h2>\n<p>\u4f7f\u7528 <code>getFirstSubstringIndex<\/code> \u4f86\u6c42\u51fa\u5b57\u4e32\u4e2d\u9996\u500b\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u64f7\u53d6\u5b57\u4e32\u4e2d\u7684\u67d0\u500b\u5b50\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u78bc\u4f86\u64f7\u53d6 <code>str<\/code> \u4e2d\u7684 <code>World<\/code> \u5b50\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet str = \"Hello World\";\nlet index = str.getFirstSubstringIndex(\"World\");\nlet subStr = str.substring(index, index + \"World\".length);\nconsole.log(subStr); \/\/ World\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u5148\u4f7f\u7528 <code>getFirstSubstringIndex<\/code> \u4f86\u6c42\u51fa\u5b57\u4e32\u4e2d\u9996\u500b\u5b50\u5b57\u7b26\u4e32 <code>World<\/code> \u7684\u4f4d\u7f6e\uff0c\u63a5\u8457\u4f7f\u7528 <code>substring<\/code> \u4f86\u64f7\u53d6 <code>str<\/code> \u4e2d\u7684 <code>World<\/code> \u5b50\u5b57\u7b26\u4e32\uff0c\u6700\u5f8c\u5c07\u7d50\u679c\u8f38\u51fa\u5230\u63a7\u5236\u53f0\uff0c\u7d50\u679c\u70ba <code>World<\/code>\u3002<\/p>\n<h2>\u66ff\u63db\u5b57\u4e32\u4e2d\u7684\u67d0\u500b\u5b50\u5b57\u7b26\u4e32<\/h2>\n<p>\u4f7f\u7528 <code>getFirstSubstringIndex<\/code> \u4f86\u6c42\u51fa\u5b57\u4e32\u4e2d\u9996\u500b\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u66ff\u63db\u5b57\u4e32\u4e2d\u7684\u67d0\u500b\u5b50\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u78bc\u4f86\u5c07 <code>str<\/code> \u4e2d\u7684 <code>World<\/code> \u5b50\u5b57\u7b26\u4e32\u66ff\u63db\u70ba <code>TypeScript<\/code>\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet str = \"Hello World\";\nlet index = str.getFirstSubstringIndex(\"World\");\nlet newStr = str.substring(0, index) + \"TypeScript\" + str.substring(index + \"World\".length);\nconsole.log(newStr); \/\/ Hello TypeScript\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u5148\u4f7f\u7528 <code>getFirstSubstringIndex<\/code> \u4f86\u6c42\u51fa\u5b57\u4e32\u4e2d\u9996\u500b\u5b50\u5b57\u7b26\u4e32 <code>World<\/code> \u7684\u4f4d\u7f6e\uff0c\u63a5\u8457\u4f7f\u7528 <code>substring<\/code> \u4f86\u5c07 <code>str<\/code> \u4e2d\u7684 <code>World<\/code> \u5b50\u5b57\u7b26\u4e32\u66ff\u63db\u70ba <code>TypeScript<\/code>\uff0c\u6700\u5f8c\u5c07\u7d50\u679c\u8f38\u51fa\u5230\u63a7\u5236\u53f0\uff0c\u7d50\u679c\u70ba <code>Hello TypeScript<\/code>\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728 TypeScript \u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528 <code>getFirstSubstringIndex<\/code> \u4f86\u6c42\u51fa\u5b57\u4e32\u4e2d\u9996\u500b\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u64cd\u4f5c\u5b57\u4e32\uff0c\u4f8b\u5982\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u64f7\u53d6\u5b57\u4e32\u4e2d\u7684\u67d0\u500b\u5b50\u5b57\u7b26\u4e32\uff0c\u6216\u662f\u66f4\u5bb9\u6613\u5730\u66ff\u63db\u5b57\u4e32\u4e2d\u7684\u67d0\u500b\u5b50\u5b57\u7b26\u4e32\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528TypeScript\u4e2d\u7684getFirstSubstringIndex\u51fd\u6578\uff0c\u8a72\u51fd\u6578\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u5feb\u901f\u67e5\u627e\u5b57\u4e32\u4e2d\u7684\u9996\u5b50\u5b57\u7b26\u4e32\u4f4d\u7f6e\uff0c\u4e26\u63d0\u4f9b\u7c21\u55ae\u6613\u7528\u7684API\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u4f7f\u7528\u5b83\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-5182","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-1lA","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5182","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=5182"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5182\/revisions"}],"predecessor-version":[{"id":5183,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5182\/revisions\/5183"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}