Skip to content

Commit 5fda9e0

Browse files
committed
Create 1910-remove-all-occurrences-of-a-substring.rs
1 parent d432f24 commit 5fda9e0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Rust str API: split_once
2+
3+
pub fn remove_occurrences(s: String, part: String) -> String {
4+
let mut ret = s;
5+
loop {
6+
let parts = ret.split_once(&part);
7+
if parts == None {
8+
break
9+
} else {
10+
let uwparts = parts.unwrap();
11+
ret = vec![uwparts.0, uwparts.1].join("");
12+
}
13+
}
14+
ret
15+
}
16+
17+
fn main() {
18+
let s = "aabababa".to_string();
19+
let part = "aba".to_string();
20+
println!("{:?}", remove_occurrences(s, part));
21+
}

0 commit comments

Comments
 (0)