split_string.go 280 B

12345678910111213141516
  1. package main
  2. import "fmt"
  3. func main() {
  4. str := "Google"
  5. for i := 0; i <= len(str); i++ {
  6. a, b := Split(str, i)
  7. fmt.Printf("The string %s split at position %d is: %s / %s\n", str, i, a, b)
  8. }
  9. }
  10. func Split(s string, pos int) (string, string) {
  11. return s[0:pos], s[pos:]
  12. }