pub fn substr_end(s: &str, start_index: isize) -> StringExpand description
Get a substring from character index ‘start_index’ till end of the string. ‘start_index’ can be negative to count backwards from the end. If start_index exceeds the string boundary limits, return an empty string (0, 0). (Similar to C++ std::substr() and c# String.Substring.) Index of the first character is 0.
Examples found in repository?
examples/main.rs (line 31)
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 println!("substr: {}", s2.substr(5, isize::MAX)); // "56789"
16
17 println!("substru: {}", substru(s1, 3, 2)); // "34"
18 println!("substru: {}", s1.substru(3, 2)); // "34"
19 println!("substru: {}", s2.substru(3, 2)); // "34"
20
21 println!("substring: {}", substring(s1, 3, 5)); // "34"
22 println!("substring: {}", s1.substring(3, 5)); // "34"
23
24 println!("substr: {}", substr(s1, -2, 2)); // "89", last 2 characters
25
26 println!("substr: {}", substr(s1, -10, 1)); // 0
27 println!("substr: {}", substr(s1, 0, 1)); // 0
28
29 println!("substr: {}", substr(s1, 6, isize::MAX)); // "6789"
30
31 println!("substr_end: {}", substr_end(s1, 6)); // "6789", last 2 characters
32 println!("substr_end: {}", s1.substr_end(6)); // "6789", last 2 characters
33
34 println!("str_remove: {}", str_remove(s1, 3, 2)); // "01256789"
35 println!("str_remove: {}", s1.str_remove(3, 2)); // "01256789"
36
37 match s1.indexof("234", 0) {
38 // Result: Some(2)
39 Some(pos) => println!("Found at position: {}", pos),
40 None => println!("Not found"),
41 }
42
43 println!("str_concat: {}", str_concat!(s1, " ", &s2)); // "0123456789 0123456789"
44 println!("str_concat: {}", str_concat!(s1, " ", s1)); // "0123456789 0123456789"
45}