Function str_remove

Source
pub fn str_remove(s: &str, start_index: usize, length: usize) -> String
Expand description

Remove a substring from a string. Beginning at character index ‘start_index’ and take ‘length’ characters. Index of the first character is 0.

Examples found in repository?
examples/main.rs (line 33)
4fn main() {
5    // let s1: &str = "test éèçà 123 test";
6    // let s2: String = s1.to_owned();
7
8    let s1: &str = "0123456789";
9    let s2: String = s1.to_owned();
10
11    println!("substr: {}", substr(s1, 3, 2)); // "34"
12    println!("substr: {}", substr(&s2, 3, 2)); // "34"
13    println!("substr: {}", s1.substr(3, 2)); // "34"
14    println!("substr: {}", s2.substr(3, 2)); // "34"
15
16    println!("substru: {}", substru(s1, 3, 2)); // "34"
17    println!("substru: {}", s1.substru(3, 2)); // "34"
18    println!("substru: {}", s2.substru(3, 2)); // "34"
19
20    println!("substring: {}", substring(s1, 3, 5)); // "34"
21    println!("substring: {}", s1.substring(3, 5)); // "34"
22
23    println!("substr: {}", substr(s1, -2, 2)); // "89", last 2 characters
24
25    println!("substr: {}", substr(s1, -10, 1)); // 0
26    println!("substr: {}", substr(s1, 0, 1)); // 0
27
28    println!("substr: {}", substr(s1, 6, isize::MAX)); // "6789"
29
30    println!("substr_end: {}", substr_end(s1, 6)); // "6789", last 2 characters
31    println!("substr_end: {}", s1.substr_end(6)); // "6789", last 2 characters
32
33    println!("str_remove: {}", str_remove(s1, 3, 2)); // "01256789"
34    println!("str_remove: {}", s1.str_remove(3, 2)); // "01256789"
35
36    match s1.indexof("234", 0) {
37        // Result: Some(2)
38        Some(pos) => println!("Found at position: {}", pos),
39        None => println!("Not found"),
40    }
41
42    println!("str_concat: {}", str_concat!(s1, " ", &s2)); // "0123456789 0123456789"
43    println!("str_concat: {}", str_concat!(s1, " ", s1)); // "0123456789 0123456789"
44}