Rust的标准库中是否存在find
函数,该函数从字符串中的给定索引开始搜索子字符串?就像JavaScript中的 indexOf
一样。
最佳答案
您可以在substr上使用 str::find
,然后再添加偏移量:
let s = "foobarfoo";
let index: Option<usize> = s[4..].find("foo").map(|i| i + 4);
println!("{:?}", index);
Some(6)
关于rust - 如何在Rust中从特定索引开始的子字符串中查找?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66272984/