Crates.io | strsplit |
lib.rs | strsplit |
version | 0.1.1 |
source | src |
created_at | 2024-04-18 14:33:56.208088 |
updated_at | 2024-04-18 14:36:42.276964 |
description | Split a string slice using a delimiter of your choice |
homepage | |
repository | https://github.com/amschel99/strsplit |
max_upload_size | |
id | 1212608 |
size | 4,459 |
strsplit
is a crate that provides a Strsplit
struct and a utility function until_char
for splitting strings efficiently.
Add this to your Cargo.toml
:
[dependencies]
strsplit = "0.1.1"
Then you can use it in your code:
use strsplit::Strsplit;
let haystack = "a,b,c,d,e,f";
let letters: Vec<_> = Strsplit::new(&haystack, ",").collect();
assert_eq!(letters, vec!["a", "b", "c", "d", "e", "f"]);
The until_char function returns the string before the first instance of the delimiter is found.
use strsplit::until_char;
let haystack = "hello";
let trimmed = until_char(&haystack, 'o');
assert_eq!(trimmed, "hell");