pub trait Substring {
// Required method
fn substring(&self, start_index: usize, end_index: usize) -> &str;
}
Expand description
Provides a substring()
method.
The substring()
method obtains a string slice of characters within the range specified by
start_index
and end_index
.
Required Methods§
Implementations on Foreign Types§
Source§impl Substring for str
Implements a substring()
method for str
.
impl Substring for str
Implements a substring()
method for str
.
Note that structs which implement Deref<Target=str>
(such as String
) will also have
access to this implementation.
Source§fn substring(&self, start_index: usize, end_index: usize) -> &str
fn substring(&self, start_index: usize, end_index: usize) -> &str
Obtain a slice of the characters within the range of start_index
and end_index
.
As this is by character index, rather than byte index, the temporal complexity of finding a substring is O(n), where n is the byte length of the string.
Example:
use substring::Substring;
assert_eq!("foobar".substring(2,5), "oba");