* buc...@gmail.com <buc...@gmail.com> [180220 15:51]:
> 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)
>     }
>   }
> }

Look at https://play.golang.org/p/2tz2asuZcGc where I have changed

    fmt.Println(tmp)
to
    fmt.Printf("%#v\n", tmp)

and I think you will understand that tmp does not contain what you
thought it did.  Split splits the string at "/", not at "/" and " ", so
tmp contains four strings, "this", "that there", "here that", and
"this".

...Marvin

-- 
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