[−][src]Crate substring
Substring method for string types.
This crate provides a substring
method on both String
and &str
types. The method takes a
start and end character index and returns a string slice of the characters within that range.
The method is provided via the Substring
trait which is implemented on both String
and
&str
.
Example
use substring::Substring; // Works on a string slice. assert_eq!("foobar".substring(2,5), "oba"); // Also works on a String. assert_eq!("foobar".to_string().substring(1,6), "oobar");
As Rust strings are UTF-8, the algorithm for finding a character substring is O(n)
, where n
is the byte length of the string. This is due to characters not being of predictible byte
lengths.
Traits
Substring | Provides a |