且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Rust中从特定索引开始的子字符串中查找?

更新时间:2023-11-14 23:08:58

您将使用

You would use str::find on a substr and then add the offset back:

let s = "foobarfoo";
let index: Option<usize> = s[4..].find("foo").map(|i| i + 4);
println!("{:?}", index);

Some(6)