#return dinamic data string

4 messages · Page 1 of 1 (latest)

ornate escarp
#
package main

import (
    "fmt"
)

func FindSimilarData(input string, data ...string) string {
same := ""
    for _, d := range data {
        fmt.Println(d)

        if (d) == input {
            same += d
            fmt.Println(d)
            fmt.Println(same)
        }
    }
    return "" 
}

func main() {
    fmt.Println(FindSimilarData("iphone", "laptop", "iphone 13", "iphone 12", "iphone 12 pro"))
} 

expect output is : iphone 13,iphone 12, iphone 12 pro

i want to return the data type string which has similar data, i was trying to use strings.Contains but it only returns the boolean type. can anyone give an example for this one, thanks before

keen parrot
#

You want to return a slice of strings

#

At the top: same := []string{}
In the loop:

if strings.Contains(d, input) {
  same = append(same, d)
}