index_in_string.go 516 B

123456789101112131415161718192021
  1. package main
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. func main() {
  7. var str string = "Hi, I'm Marc, Hi."
  8. fmt.Printf("The position of \"Marc\" is: ")
  9. fmt.Printf("%d\n", strings.Index(str, "Marc"))
  10. fmt.Printf("The position of the first instance of \"Hi\" is: ")
  11. fmt.Printf("%d\n", strings.Index(str, "Hi"))
  12. fmt.Printf("The position of the last instance of \"Hi\" is: ")
  13. fmt.Printf("%d\n", strings.LastIndex(str, "Hi"))
  14. fmt.Printf("The position of \"Burger\" is: ")
  15. fmt.Printf("%d\n", strings.Index(str, "Burger"))
  16. }