I have a string and I need to scan for every occurrence of "foo" and read all the text following it until a second "
. Since Rust does not have a , I need to iterate by characters scanning for it. How would I do this?contains
function for strings
Edit: Rust's &str
has a contains()
and find()
method.
The
.chars()
method returns an iterator over characters in a string. e.g.If you are interested in the byte offsets of each char, you can use
char_indices
.Look into
.peekable()
, and usepeek()
for looking ahead. It's wrapped like this because it supports UTF-8 codepoints instead of being a simple vector of characters.You could also create a vector of
char
s and work on it from there, but that's more time and space intensive: