1 unstable release
0.0.0 | Apr 26, 2023 |
---|
#142 in #split
55 downloads per month
4KB
Split First Char
A small utility to split a string into the first character (type char
) and the rest (type &str
).
Usage
Function call
use split_first_char::split_first_char;
let (first_char, rest) = split_first_char("abc").unwrap();
assert_eq!(first_char, 'a');
assert_eq!(rest, "bc");
Method call
use split_first_char::SplitFirstChar;
let (first_char, rest) = "abc".split_first_char().unwrap();
assert_eq!(first_char, 'a');
assert_eq!(rest, "bc");
Alternative
If you don't need the first character to be a char
, just use str.split_at(1)
, it will return a tuple of 2 strings.