Maybe this will help understand what Split() does:

https://play.golang.org/p/U7gkrBs8IaZ

func main() {
  s := "this/that there/here that/this"
  tmp := strings.Split(s, "/")
  fmt.Printf("%#v\n", tmp)
}

Output:
[]string{"this", "that there", "here that", "this"}

So when you loop over strings, it's expected the loop will pick up "that 
there" and "here that".


On Tuesday, February 20, 2018 at 12:50:49 PM UTC-8, buc...@gmail.com wrote:
>
> package main
>
> import (
>   "fmt"
>   "strings"
> )
>
> func main() }
>   s := "this/that there/here that/this"
>   tmp := strings.Split(s, "/")
>   fmt.Println(tmp)
>   for _, s1 := range tmp {
> if strings.Contains(s1, "that") {
> fmt.Println(s1)
> }
>   }
> }
>
> Output:
> this was as expected:
> [this that there here that this]
>
> this was NOT expected:
> that there
> here that
>
> By my reasoning, each loop through the range of tmp, s1 should have 
> grabbed one word from the tmp slice and made the comparison with that word 
> alone.  But instead the second fmt.Println() output implies that it grabbed 
> more than one word.
>
> I'm a noob and puzzled by this behavior.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to