How can I find the index of a character in a string in Rust?
Although a little more convoluted than I would like, another solution is to use the Chars iterator and its position() function: “Program”.chars().position(|c| c == ‘g’).unwrap() find used in the accepted solution returns the byte offset and not necessarily the index of the character. It works fine with basic ASCII strings, such as the one in … Read more