在 Go 中拆分字符串列表中的字符串
Splitting a string on a list of strings in Go
是否可以不仅拆分一个字符串而且拆分一段字符串?即
strings.Split("Dogs and Cats are Great", "and"))
但不是使用一个字符串,而是像这样使用一段字符串:
strings.Split("Dogs and Cats are Great", []string{"and", "are"}))
您可以使用正则表达式:http://play.golang.org/p/vCRCv4rt7s
re := regexp.MustCompile(`and|are`)
fmt.Printf("%q\n", re.Split("Dogs and Cats are Great", -1))
是否可以不仅拆分一个字符串而且拆分一段字符串?即
strings.Split("Dogs and Cats are Great", "and"))
但不是使用一个字符串,而是像这样使用一段字符串:
strings.Split("Dogs and Cats are Great", []string{"and", "are"}))
您可以使用正则表达式:http://play.golang.org/p/vCRCv4rt7s
re := regexp.MustCompile(`and|are`)
fmt.Printf("%q\n", re.Split("Dogs and Cats are Great", -1))