How to find the last index of a value in slice of bytes in Go

2 Answers

0 votes
package main
 
import (
    "fmt"
    "bytes"
)
 
func main() {
    lastindex := bytes.LastIndex([]byte("abccdbdbefbbxyz"),[]byte("b")) 
     
    fmt.Printf("%d", lastindex)    
}
 
 
 
/*
run:
 
11
 
*/

 



answered May 25, 2020 by avibootz
edited May 25, 2020 by avibootz
0 votes
package main
 
import (
    "fmt"
    "bytes"
)
 
func main() {
    slice := []byte{'G', 'O', ' ' , '1', '.', 'a', '1', '4', '.', 'a', '2'} 
    
    lastindex := bytes.LastIndex(slice, []byte("a")) 
     
    fmt.Printf("%d", lastindex)    
}
 
 
 
/*
run:
 
9
 
*/

 



answered May 25, 2020 by avibootz
...