diff --git "a/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/README.md" index 892d62429130b..219c29b6b8824 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/README.md" @@ -130,12 +130,26 @@ public: ### **TypeScript** +- 使用 `replace()` + ```ts function replaceSpace(s: string): string { return s.replace(/\s/g, "%20"); } ``` +- 遍历添加 + +```ts +function replaceSpace(s: string): string { + const strArr = []; + for (const c of s) { + strArr.push(c === " " ? "%20" : c); + } + return strArr.join(""); +} +``` + ### **...** ```