How can I find a subsequence in a &[u8] slice?

后端 未结 4 1197
耶瑟儿~
耶瑟儿~ 2020-12-03 20:45

I have a &[u8] slice over a binary buffer. I need to parse it, but a lot of the methods that I would like to use (such as str::find) don\'t see

4条回答
  •  一生所求
    2020-12-03 21:29

    I found the memmem crate useful for this task:

    use memmem::{Searcher, TwoWaySearcher};
    
    let search = TwoWaySearcher::new("dog".as_bytes());
    assert_eq!(
        search.search_in("The quick brown fox jumped over the lazy dog.".as_bytes()),
        Some(41)
    );
    

提交回复
热议问题