Finding index of a one of number of characters

Having string let's say 01c23a45b6, what is the most idiomatic way to find the position of either 'a', 'b' or 'c' char in that string?

println!("{:?}", "0123a456".find("a"));
1 Like

Hi and thanks.
And how to go about finding one of let's say few, that is I would like to find first of (a,b or c)?

Please read the documentation for str::find(). It explicitly states that:

So, you can use ['a', 'b', 'c'].as_slice() in the argument.


I think as slice is being called on unstable fixed_size_array?

You can use as_ref() or &['a', 'b', 'c'][..] as well, it doesn't matter.