File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,36 @@ function replaceSpace(s: string): string {
151
151
}
152
152
```
153
153
154
+ ### ** Rust**
155
+
156
+ - 使用 ` replace() `
157
+
158
+ ``` rust
159
+ impl Solution {
160
+ pub fn replace_space (s : String ) -> String {
161
+ s . replace (' ' , " %20" )
162
+ }
163
+ }
164
+ ```
165
+
166
+ - 遍历添加
167
+
168
+ ``` rust
169
+ impl Solution {
170
+ pub fn replace_space (s : String ) -> String {
171
+ let mut result = String :: new ();
172
+ for c in s . chars () {
173
+ if c == ' ' {
174
+ result . push_str (" %20" );
175
+ } else {
176
+ result . push (c );
177
+ }
178
+ }
179
+ result
180
+ }
181
+ }
182
+ ```
183
+
154
184
### ** ...**
155
185
156
186
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn replace_space ( s : String ) -> String {
3
+ s. replace ( ' ' , "%20" )
4
+ }
5
+ }
You can’t perform that action at this time.
0 commit comments