下面介绍使用fuzzy.Find和string.Contains分别进行模糊查询
package main
import(
"github.com/lithammer/fuzzysearch/fuzzy"
"strings"
"fmt"
)
func main() {
//fuzzy
words := []string{"cartwheel", "foobar", "wheel", "baz"}
match1 :=fuzzy.Find("whl", words) // [cartwheel wheel]
fmt.Println("match1:", match1)
//strings.Contains
a := "10.11.12.13"
c := "12.13"
match2 := strings.Contains(a, c)
fmt.Println("match2:", match2)
}
返回结果如下:
match1: [cartwheel wheel]
match2: true
即fuzzy.Find返回的是匹配到的值,string.Contains返回的是bool型结果。