当前位置: 首页>>代码示例>>Golang>>正文


Golang strings.ContainsAny函数代码示例

本文整理汇总了Golang中strings.ContainsAny函数的典型用法代码示例。如果您正苦于以下问题:Golang ContainsAny函数的具体用法?Golang ContainsAny怎么用?Golang ContainsAny使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ContainsAny函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	fmt.Println(strings.Index("chicken", "ken"))
	fmt.Println(strings.Index("chicken", "dmr"))

	fmt.Println(strings.ContainsAny("team", "e"))
	fmt.Println(strings.ContainsAny("failure", "u & i"))
	fmt.Println(strings.ContainsAny("foo", ""))
	fmt.Println(strings.ContainsAny("", ""))

	fmt.Println(1 & 1)
	fmt.Println(2 & 1)
	fmt.Println(4 & 1)
	fmt.Println(5 & 1)

	pow, sq := HashTest("1234567")
	fmt.Println(pow)
	fmt.Println(sq)

	str := "df 世 界 asd"
	s := "1界"
	index := strings.IndexAny(str, "界")
	fmt.Printf("%d......\n", index)
	for i, c := range str {
		fmt.Println(i)
		for _, m := range s {
			fmt.Printf("%c\t%c\n", c, m)
		}
	}

	for i := len(str); i > 0; {
		rune, size := utf8.DecodeLastRuneInString(str[0:i])
		fmt.Printf("%v\t", i)
		i -= size
		for _, m := range s {
			fmt.Printf("%c\t%v\t%v\n", rune, size, m)
		}
	}

	fmt.Println("bytes =", len(str))
	fmt.Println("runes =", utf8.RuneCountInString(str))

	for _, ss := range strings.Fields(str) {
		fmt.Println(ss)

	}
	fmt.Println(strings.ToTitle(str))

	str = "Hello, 世界"

	// for len(str) > 0 {
	// 	r, size := utf8.DecodeRuneInString(str)
	// 	fmt.Printf("%c %v\n", r, size)

	// 	str = str[size:]
	// }
	fmt.Println(Replace(str, "", "f", -1))

	hulu := new(huluwa)
	hello(hulu)
}
开发者ID:suifengRock,项目名称:go-source,代码行数:60,代码来源:main.go

示例2: TestKillWithInvalidSignal

func (s *DockerSuite) TestKillWithInvalidSignal(c *check.C) {
	testRequires(c, DaemonIsLinux)
	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
	cid := strings.TrimSpace(out)
	c.Assert(waitRun(cid), check.IsNil)

	out, _, err := dockerCmdWithError("kill", "-s", "0", cid)
	c.Assert(err, check.NotNil)
	if !strings.ContainsAny(out, "Invalid signal: 0") {
		c.Fatal("Kill with an invalid signal didn't error out correctly")
	}

	running, _ := inspectField(cid, "State.Running")
	if running != "true" {
		c.Fatal("Container should be in running state after an invalid signal")
	}

	out, _ = dockerCmd(c, "run", "-d", "busybox", "top")
	cid = strings.TrimSpace(out)
	c.Assert(waitRun(cid), check.IsNil)

	out, _, err = dockerCmdWithError("kill", "-s", "SIG42", cid)
	c.Assert(err, check.NotNil)
	if !strings.ContainsAny(out, "Invalid signal: SIG42") {
		c.Fatal("Kill with an invalid signal error out correctly")
	}

	running, _ = inspectField(cid, "State.Running")
	if running != "true" {
		c.Fatal("Container should be in running state after an invalid signal")
	}
}
开发者ID:waterytowers,项目名称:global-hack-day-3,代码行数:32,代码来源:docker_cli_kill_test.go

示例3: testGenericRecursive

func testGenericRecursive(t *testing.T, beforeErr error, beforeWant []string, list []wrapper, maxDepth int) {
	if len(beforeWant) == 0 {
		panic("beforeWant must not be empty")
	}
	for _, w := range list {
		if len(w.want) == 0 {
			panic("want must not be empty")
		}

		err := w.wrap(beforeErr)

		// Copy required cause append(beforeWant, ..) modified beforeWant subtly.
		beforeCopy := make([]string, len(beforeWant))
		copy(beforeCopy, beforeWant)

		beforeWant := beforeCopy
		last := len(beforeWant) - 1
		var want []string

		// Merge two stacks behind each other.
		if strings.ContainsAny(beforeWant[last], "\n") && strings.ContainsAny(w.want[0], "\n") {
			want = append(beforeWant[:last], append([]string{beforeWant[last] + "((?s).*)" + w.want[0]}, w.want[1:]...)...)
		} else {
			want = append(beforeWant, w.want...)
		}

		testFormatCompleteCompare(t, maxDepth, err, "%+v", want, false)
		if maxDepth > 0 {
			testGenericRecursive(t, err, want, list, maxDepth-1)
		}
	}
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:32,代码来源:format_test.go

示例4: findVideoId

// reads the videoId property and try to find what we need inside
func (cfg *Config) findVideoId() (videoId string, err error) {
	videoId = cfg.videoId
	if strings.Contains(videoId, "youtu") || strings.ContainsAny(videoId, "\"?&/<%=") {
		log("Provided video id seems to be an url, trying to detect")
		re_list := []*regexp.Regexp{
			regexp.MustCompile(`(?:v|embed|watch\?v)(?:=|/)([^"&?/=%]{11})`),
			regexp.MustCompile(`(?:=|/)([^"&?/=%]{11})`),
			regexp.MustCompile(`([^"&?/=%]{11})`),
		}
		for _, re := range re_list {
			if is_match := re.MatchString(videoId); is_match {
				subs := re.FindStringSubmatch(videoId)
				videoId = subs[1]
			}
		}
	}
	log("Found video id: '%s'", videoId)
	if strings.ContainsAny(videoId, "?&/<%=") {
		return videoId, errors.New("invalid characters in video id")
	}
	if len(videoId) < 10 {
		return videoId, errors.New("the video id must be at least 10 characters long")
	}
	return videoId, nil
}
开发者ID:sujonmiya,项目名称:youtube-dl,代码行数:26,代码来源:config.go

示例5: preprocess

func preprocess(input string) (string, bool, bool) {
	ok := true
	end := false
	output := input
	var buffer bytes.Buffer

	//skip words with numerals
	nums := "1234567890"
	if strings.ContainsAny(input, nums) {
		ok = false
		return output, ok, end
	}

	//remove parenthesis
	i := strings.IndexAny(input, "()")
	if i > -1 {
		buffer.WriteString(input[:i])
		buffer.WriteString(input[i+1:])
		output = buffer.String()
	}

	if strings.ContainsAny(input, ".!?") {
		end = true
	}

	return output, ok, end
}
开发者ID:Albrektson,项目名称:markov,代码行数:27,代码来源:markov.go

示例6: GetBlog

func GetBlog(w http.ResponseWriter, r *http.Request) {
	u := User{}

	// Check if offset and limit were provided for pagination
	vars := mux.Vars(r)
	offset, err := strconv.Atoi(vars["offset"])
	if err != nil {
		// If var is empty assign default value
		if strings.ContainsAny(err.Error(), "invalid syntax") {
			offset = 0
		} else {
			log.Printf("No offset query parameter: %s", err)
		}
	}
	limit, err := strconv.Atoi(vars["limit"])
	if err != nil {
		// If var is empty assign default value
		if strings.ContainsAny(err.Error(), "invalid syntax") {
			limit = 10
		} else {
			log.Printf("No offset query parameter: %s", err)
		}
	}

	b, err := selectPageBlogEntries(limit, offset)
	if err != nil {
		log.Printf("ERROR: could not retrieve blog entries")
	}

	bFmt := []Post{}
	for _, post := range b {
		blogpost := Post{
			Id:       post.Id,
			Postdate: post.PostDate.Format("15:04:05 Mon Jan 2 2006"),
			Title:    post.Title,
			Tags:     post.Tags,
			Body:     template.HTML(string(blackfriday.MarkdownCommon([]byte(post.Body)))),
		}
		bFmt = append(bFmt, blogpost)
	}

	data := struct {
		Blog []Post
		User User
	}{
		bFmt,
		u,
	}

	t, err := template.ParseFiles("tmpl/base.html",
		"tmpl/header.tmpl",
		"tmpl/navbar.tmpl",
		"tmpl/blog-body.tmpl",
		"tmpl/footer.tmpl",
		"tmpl/js.tmpl")
	if err != nil {
		log.Printf("ERROR: error creating blog HTML template: %s", err)
	}
	t.Execute(w, data)
}
开发者ID:MajorMJR,项目名称:homesite,代码行数:60,代码来源:handlers.go

示例7: ConvertBandwidth

//ConvertBandwidth will change the format of the bandwidth to int64 format and return the updated bw.
//eg:- 2 kb bandwidth will be converted to 2*1024 and the result in Int64 format will be returned.
func ConvertBandwidth(bandwidth string) int64 {
	var rate int64

	const (
		kilobytes = 1024
		megabytes = 1024 * kilobytes
		gigabytes = 1024 * megabytes
	)

	regex := regexp.MustCompile("[0-9]+")
	bw := regex.FindAllString(bandwidth, -1)
	bwParseInt, err := strconv.ParseInt(bw[0], 10, 64)
	if err != nil {
		log.Errorf("error converting bandwidth string to uint64 %+v", err)
	}
	if strings.ContainsAny(bandwidth, "g|G") {
		rate = gigabytes
	} else if strings.ContainsAny(bandwidth, "m|M") {
		rate = megabytes
	} else if strings.ContainsAny(bandwidth, "k|K") {
		rate = kilobytes
	}
	bwInt := bwParseInt * rate
	bwInt = bwInt / 1000

	return bwInt
}
开发者ID:jojimt,项目名称:netplugin,代码行数:29,代码来源:netutils.go

示例8: ContainsAny

// ContainsAny reports whether any Unicode code points in chars within s
func ContainsAny(s, chars string) bool {
	fmt.Println(strings.ContainsAny("team", "i"))        // false
	fmt.Println(strings.ContainsAny("failure", "u & i")) // true
	fmt.Println(strings.ContainsAny("foo", ""))          // false
	fmt.Println(strings.ContainsAny("", ""))             // false
	return strings.ContainsAny(s, chars)
}
开发者ID:upccup,项目名称:cuplearn,代码行数:8,代码来源:stringsTest.go

示例9: BwConvertInt64

func BwConvertInt64(bandwidth string) (int64, error) {
	var rate int64

	const (
		kiloBytes = 1024
		magaBytes = 1024 * kiloBytes
		gigaBytes = 1024 * magaBytes
	)

	regex := regexp.MustCompile("[0-9]+")
	bwStr := regex.FindAllString(bandwidth, -1)
	bwInt, err := strconv.ParseInt(bwStr[0], 10, 64)
	if err != nil {
		logrus.Errorf("error converting bandwidth string to uint64 %+v", err)
		return 0, err
	}
	if strings.ContainsAny(bandwidth, "g|G") {
		rate = gigaBytes
	} else if strings.ContainsAny(bandwidth, "m|M") {
		rate = magaBytes
	} else if strings.ContainsAny(bandwidth, "k|K") {
		rate = kiloBytes
	}
	bwInt64 := bwInt * rate
	bwInt64 = bwInt64 / 1000

	return bwInt64, nil
}
开发者ID:jojimt,项目名称:netplugin,代码行数:28,代码来源:docker_test.go

示例10: cuter

func cuter(line string) (it Item, suc bool) {
	items := strings.FieldsFunc(line, fieldFilter)
	if len(items) < 2 {
		// fmt.Println(line)
		return it, false
	}

	it.word = strings.Replace(items[0], " ", "", -1)
	ext_start := 1
	for ; ext_start < len(items); ext_start++ {
		if strings.ContainsAny(items[ext_start], "[]【】") {
			it.ext += strings.Trim(items[ext_start], "[]【】><+ \t")
		} else {
			break
		}
	}

	meanings := ""
	for i := ext_start; i < len(items); i++ {
		if strings.ContainsAny(items[i], "0123456789") {
			if len(meanings) != 0 {
				meanings += "-"
			}
			meanings += strings.Trim(items[i], "[]【】 \t\r\n-")
		}
	}
	if len(meanings) == 0 {
		meanings = items[ext_start]
	}
	it.meanings = strings.Split(meanings, "-")
	return it, true
}
开发者ID:rosrad,项目名称:grid,代码行数:32,代码来源:jp-import.go

示例11: check_syntax

func check_syntax(insane string) bool {
	/* State machine; Sane == S3, S1
	~	0\-9		,		-		*		/
	S0	S + 2		Err		Err		S + 3	Err
	S1	Err			Err		Err		Err		Err
	S2	S++			Err		Err		Err		Err
	S3	Err			S - 3	S + 2	Err		S + 2
	S4	S -	3		Err		Err		Err		Err
	S5	S--			Err		Err		Err		Err
	*/

	state := 0
	for i := 0; i != len(insane); i++ {
		if strings.ContainsAny(string(insane[i]), "0123456789") {
			if state == 0 {
				state += 2
			} else if state == 2 {
				state++
			} else if state == 4 {
				state -= 3
			} else if state == 5 {
				state--
			} else {
				return false
			}
		} else if strings.ContainsAny(string(insane[i]), ",") {
			if state == 3 {
				state -= 3
			} else {
				return false
			}
		} else if strings.ContainsAny(string(insane[i]), "-") {
			if state == 3 {
				state += 2
			} else {
				return false
			}
		} else if strings.ContainsAny(string(insane[i]), "*") {
			if state == 0 {
				state += 3
			} else {
				return false
			}
		} else if strings.ContainsAny(string(insane[i]), "/") {
			if state == 3 {
				state += 2
			} else {
				return false
			}
		} else {
			return false
		}
	}
	if state == 3 || state == 1 {
		return true
	} else {
		return false
	}
}
开发者ID:Horrendus,项目名称:beehive,代码行数:59,代码来源:cronparser.go

示例12: main

func main() {

	defer func() {
		if r := recover(); r != nil {
			fmt.Println(r)
			os.Exit(1)
		}
	}()

	utils.LogInfo("\nDeploying Agent Server...")

	var ln string
	var e error
	rd := bufio.NewReader(os.Stdin)

	for {
		ln, e = rd.ReadString('\n')
		println(ln)
		if e != nil {
			panic(e)
		} else if strings.ContainsAny(ln, "AGENT_KUBER_API") {
			break
		}
	}

	if !strings.ContainsAny(ln, "AGENT_KUBER_API") {
		panic("Missing Key, AGENT_KUBER_API. Cannot proceed.")
	}

	kv := strings.Split(ln, "=")
	utils.SetKey("AGENT_KUBER_API", kv[1])

	pk, puk, _ := utils.CreateSSHKey()

	c := deploy.CenturyLink{
		PublicSSHKey:   puk,
		APIUsername:    os.Getenv("USERNAME"),
		APIPassword:    os.Getenv("PASSWORD"),
		GroupID:        os.Getenv("GROUP_ID"),
		CPU:            1,
		MemoryGB:       1,
		TCPOpenPorts:   []int{3001},
		ServerName:     "AGENT",
		ServerTemplate: "UBUNTU-14-64-TEMPLATE",
	}

	utils.LogInfo("\nWaiting for server creation...")
	s, e := c.DeployVM()

	if e != nil {
		panic(e)
	}

	utils.SetKey("AGENT_PRIVATE_KEY", base64.StdEncoding.EncodeToString([]byte(pk)))
	utils.SetKey("AGENT_PUBLIC_IP", s.PublicIP)

	utils.LogInfo("\nAgent server deployment complete!!")
}
开发者ID:rupakg,项目名称:agent-server-deploy,代码行数:58,代码来源:deployAgent.go

示例13: TestStrings

func TestStrings() {
	fmt.Println("testStrings---------------------------------")
	a := "jiangkou jiangkou"
	b := "ang"
	fmt.Println("[a=", a, "][b=", b, "]")
	//查找某个字符是否在这个字符串中存在,存在返回true
	fmt.Println("strings.Contains(a, b) = ", strings.Contains(a, b))
	fmt.Println("strings.Contains(b, a) = ", strings.Contains(b, a))

	//查询字符串中是否包含多个字符
	c := "h&z"
	d := "i&o"
	fmt.Println("[c=", c, "][d=", d, "]")
	fmt.Println("strings.ContainsAny(a, c) = ", strings.ContainsAny(a, c))
	fmt.Println("strings.ContainsAny(a, d) = ", strings.ContainsAny(a, d))

	//一段字符串中有多少匹配到的字符
	fmt.Println("strings.Count(a, b) = ", strings.Count(a, b))

	//两个字符串在完全小写的情况下是否相等
	e := "JiAnGKOu"
	fmt.Println("e=", e)
	fmt.Println("strings.EqualFold(a, e) = ", strings.EqualFold(a, e))

	//空格来分割字符串最后返回的是[]string的切片
	f := "aa bcd efghij"
	fmt.Println("f=", f)
	fmt.Println("strings.Fields(f) = ", strings.Fields(f))

	//根据自定义函数来切分
	i := "aa|bcd_d|fgh_i|ej"
	j := '|'
	fmt.Println("[i=", i, "][j=", j, "]")
	fmt.Println(strings.FieldsFunc(i, func(s rune) bool {
		if s == rune(j) {
			return true
		}
		return false
	}))

	fmt.Println("strings.Split(i, string(j)) = ", strings.Split(i, string(j)))

	//判断是否以某个字符串开头
	g := "jia"
	fmt.Println("g=", g)
	fmt.Println("strings.HasPrefix(a, g) = ", strings.HasPrefix(a, g))

	//判断是否以某个字符串结尾
	h := "ou"
	fmt.Println("h=", h)
	fmt.Println("strings.HasSuffix(a, h) = ", strings.HasSuffix(a, h))

	// 字符串替换
	r := "welcome to shenzhen china"
	fmt.Print("orld str : ", r)
	r = strings.Replace(r, " ", ",", -1)
	fmt.Print(",replace str : ", r)
}
开发者ID:shawnpan,项目名称:learnGo,代码行数:58,代码来源:testString.go

示例14: noDotsOrDashes

func (s *XLSuite) noDotsOrDashes(rng *xr.PRNG) string {
	var length int = 3 + rng.Intn(16)
	var name = rng.NextFileName(length)
	for len(name) < 3 || strings.ContainsAny(name, ".-") ||
		strings.ContainsAny(name[0:1], "0123456789") {
		name = rng.NextFileName(length)
	}
	return name
}
开发者ID:jddixon,项目名称:xlUtil_go,代码行数:9,代码来源:entityName_test.go

示例15: main

func main() {
	fmt.Println(strings.Contains("Assume", "Ass"))

	fmt.Println(strings.ContainsAny("team", "i"))
	fmt.Println(strings.ContainsAny("Hello", "aeiou&y"))

	fmt.Println(strings.HasPrefix("Hello World", "Hello"))
	fmt.Println(strings.HasSuffix("Hello World", "World"))
}
开发者ID:rafos,项目名称:golangcookbook.github.io,代码行数:9,代码来源:test_substrings.go


注:本文中的strings.ContainsAny函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。