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


Golang strings.LastIndexAny函数代码示例

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


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

示例1: lsZip

func (p *fileSystem) lsZip(data []byte) map[string]bool {
	r, err := zip.NewReader(bytes.NewReader(data), int64(len(data)))
	if err != nil {
		return nil
	}
	ssMap := make(map[string]bool)
	for _, f := range r.File {
		if x := strings.Index(f.Name, "LC_MESSAGES"); x != -1 {
			s := strings.TrimRight(f.Name[:x], `\/`)
			if x = strings.LastIndexAny(s, `\/`); x != -1 {
				s = s[x+1:]
			}
			if s != "" {
				ssMap[s] = true
			}
			continue
		}
		if x := strings.Index(f.Name, "LC_RESOURCE"); x != -1 {
			s := strings.TrimRight(f.Name[:x], `\/`)
			if x = strings.LastIndexAny(s, `\/`); x != -1 {
				s = s[x+1:]
			}
			if s != "" {
				ssMap[s] = true
			}
			continue
		}
	}
	return ssMap
}
开发者ID:hnakamur,项目名称:gettext-go,代码行数:30,代码来源:fs.go

示例2: LastIndexAny

// LastIndexAny returns the index of the last instance of any Unicode code
// point from chars in s, or -1 if no Unicode code point from chars is present in s
func LastIndexAny(s, chars string) int {
	fmt.Println(strings.LastIndexAny("gogopher", "go"))     // 3
	fmt.Println(strings.LastIndexAny("gogopher", "ogh"))    // 5
	fmt.Println(strings.LastIndexAny("gogopher", "gr"))     // 7
	fmt.Println(strings.LastIndexAny("gogopher", "rodent")) // 7
	return strings.LastIndexAny(s, chars)
}
开发者ID:upccup,项目名称:cuplearn,代码行数:9,代码来源:stringsTest.go

示例3: GetContainerPort

func (cp ContainerPort) GetContainerPort() string {
	start := strings.LastIndexAny(string(cp), Host_Container_Separator) + 1
	end := strings.LastIndexAny(string(cp), Port_Protocol_Separator)
	if end == -1 {
		end = len(string(cp))
	}
	return string(cp)[start:end]
}
开发者ID:sdgdsffdsfff,项目名称:dockerf,代码行数:8,代码来源:portbindings.go

示例4: GetPreDir

// 获取上一层目录
func GetPreDir(dir string) string {
	dir3 := ""
	if runtime.GOOS == "windows" {
		dir2 := strings.LastIndexAny(dir, "\\")
		dir3 = dir[:dir2] + "\\"
	} else {
		dir2 := strings.LastIndexAny(dir, "/")
		dir3 = dir[:dir2] + "/"
	}
	return dir3
}
开发者ID:toophy,项目名称:login,代码行数:12,代码来源:misc.go

示例5: parseContainerPort

func (pb *PortBinding) parseContainerPort(portStr string) error {
	start := strings.LastIndexAny(portStr, ":") + 1
	end := strings.LastIndexAny(portStr, "/")
	if end == -1 {
		end = len(portStr)
	}
	cPort, err := strconv.ParseUint(portStr[start:end], 10, 32)
	if err != nil {
		return errors.New(fmt.Sprintf("Can not parse container port. %s", portStr))
	}
	pb.ContainerPort = int(cPort)
	return nil
}
开发者ID:jiangshengwu,项目名称:dockerf,代码行数:13,代码来源:portbindings.go

示例6: Create

func (this *Rotator) Create(name string, rotationByTime int) {
	if name[len(name)-1] == '\\' || name[len(name)-1] == '/' {
		this.baseFileName = name + "default.log"
	} else {
		this.baseFileName = name
	}
	if strings.LastIndexAny(name, "\\/") != -1 {
		os.MkdirAll(name[0:strings.LastIndexAny(name, "\\/")], 0766)
	}
	// fmt.Println("name:", name)
	this.rotationByTime = rotationByTime
	now := time.Now()
	this.switchFile(now)
}
开发者ID:yangzhao28,项目名称:utils,代码行数:14,代码来源:rotationfile.go

示例7: formatNotes

func formatNotes(notes []*profile.Note, width int) []string {
	if len(notes) == 0 {
		return []string{""}
	}
	var output []string
	for _, v := range notes {
		text := fmt.Sprintf("%s | %s", v.Title, v.Text)
		for _, line := range strings.Split(text, "\n") {
			if len(line) <= width {
				output = append(output, line)
				continue
			}
			rem := line
			for {
				if len(rem) <= width {
					output = append(output, rem)
					break
				}
				cur := rem[:width]
				if p := strings.LastIndexAny(cur, " ,."); p > width/2 {
					cur = cur[:p+1]
				}
				output = append(output, cur)
				rem = rem[len(cur):]
			}
		}
	}
	return output
}
开发者ID:rainycape,项目名称:gondola,代码行数:29,代码来源:profile.go

示例8: main

func main() {
	fmt.Println(strings.Index("Hello, world!", "He"))  // 0: He가 맨 처음에 있으므로 0
	fmt.Println(strings.Index("Hello, world!", "wor")) // 7: wor가 8번째에 있으므로 7
	fmt.Println(strings.Index("Hello, world!", "ow"))  // -1: ow는 없으므로 -1

	fmt.Println(strings.IndexAny("Hello, world!", "eo")) // 1: e가 2번째에 있으므로 1
	fmt.Println(strings.IndexAny("Hello, world!", "f"))  // -1: f는 없으므로 -1

	var c byte
	c = 'd'
	fmt.Println(strings.IndexByte("Hello, world!", c)) // 11: d가 12번째에 있으므로 11
	c = 'f'
	fmt.Println(strings.IndexByte("Hello, world!", c)) // -1: f는 없으므로 -1

	var r rune
	r = '언'
	fmt.Println(strings.IndexRune("고 언어", r)) // 4: "언"이 시작되는 인덱스가 4

	f := func(r rune) bool {
		return unicode.Is(unicode.Hangul, r) // r이 한글 유니코드이면 true를 리턴
	}
	fmt.Println(strings.IndexFunc("Go 언어", f))       // 3: 한글이 4번째부터 시작하므로 3
	fmt.Println(strings.IndexFunc("Go Language", f)) // -1: 한글이 없으므로 -1

	fmt.Println(strings.LastIndex("Hello Hello Hello, world!", "Hello"))
	// 12: 마지막 Hello가 13번째에 있으므로 12

	fmt.Println(strings.LastIndexAny("Hello, world", "ol")) // 10: 마지막 l이 11번째에 있으므로 10

	fmt.Println(strings.LastIndexFunc("Go 언어 안녕", f)) // 13: 마지막 한글인 '녕'이 시작되는 인덱스가 13
}
开发者ID:jemoonkim,项目名称:golangbook,代码行数:31,代码来源:strings_Index.go

示例9: BaseName

// basename for Windows and Unix (strips everything before / or \\
func BaseName(fn string) string {
	p := strings.LastIndexAny(fn, `/\`)
	if p >= 0 {
		fn = fn[p+1:]
	}
	return fn
}
开发者ID:tgulacsi,项目名称:aostor,代码行数:8,代码来源:info.go

示例10: hasExt

func hasExt(file string) bool {
	i := strings.LastIndex(file, ".")
	if i < 0 {
		return false
	}
	return strings.LastIndexAny(file, `:\/`) < i
}
开发者ID:sreis,项目名称:go,代码行数:7,代码来源:lp_windows.go

示例11: getTemperature

func (t *Thermometer) getTemperature() float64 {
	path := t.device + "/w1_slave"

	file, err := os.Open(path)
	if err != nil {
		log.Fatal(err)
	}

	defer file.Close()
	scanner := bufio.NewScanner(file)
	scanner.Split(bufio.ScanLines)

	var lines []string

	for scanner.Scan() {
		lines = append(lines, scanner.Text())
	}

	statusLine := lines[0]
	statusLineLen := len(statusLine)

	if statusLineLen < 3 || statusLine[statusLineLen-3:] != "YES" {
		log.Fatal("Temperature doesn't seem to be valid")
	}

	dataLine := lines[1]
	l := strings.LastIndexAny(dataLine, "t=")
	celsius, err := strconv.ParseFloat(dataLine[l+1:], 64)
	if err != nil {
		log.Fatal("Could not convert temperature from device")
	}

	return (celsius / 1000.0)
}
开发者ID:tomtaylor,项目名称:heating,代码行数:34,代码来源:thermometer.go

示例12: LookupImport

func (w *PkgWalker) LookupImport(pkg *types.Package, pkgInfo *types.Info, cursor *FileCursor, is *ast.ImportSpec) {
	fpath, err := strconv.Unquote(is.Path.Value)
	if err != nil {
		return
	}
	fbase := fpath
	pos := strings.LastIndexAny(fpath, "./-\\")
	if pos != -1 {
		fbase = fpath[pos+1:]
	}
	fid := fpath + "." + fbase
	//kind := ObjPkgName
	//fmt.Println(kind, true)

	if typeFindDef {
		fmt.Println(w.fset.Position(is.Pos()))
	}
	if typeFindInfo {
		fmt.Println("package", fpath)
	}
	if !typeFindUse {
		return
	}
	var usages []int
	for id, obj := range pkgInfo.Uses {
		if obj != nil && obj.Id() == fid { //!= nil && cursorObj.Pos() == obj.Pos() {
			usages = append(usages, int(id.Pos()))
		}
	}
	(sort.IntSlice(usages)).Sort()
	for _, pos := range usages {
		fmt.Println(w.fset.Position(token.Pos(pos)))
	}
}
开发者ID:RavenZZ,项目名称:liteide,代码行数:34,代码来源:type.go

示例13: zhihuDailyJson

func zhihuDailyJson(str string) UsedData {

	sj, _ := simplejson.NewJson([]byte(str))

	tmp, _ := time.Parse("20060102", sj.Get("date").MustString())
	date := tmp.Format("2006.01.02 Monday")

	news, _ := sj.Get("news").Array()

	var mainpages []MainPage
	var shareimageurl, shareimage, title string

	for _, a := range news {
		m := a.(map[string]interface{})

		url := m["url"].(string)
		id := atoi(url[strings.LastIndexAny(url, "/")+1:])

		if m["share_image"] != nil {
			shareimageurl = m["share_image"].(string)
		} else { // new api do not provide share_imag
			title = m["title"].(string)
			shareimageurl = m["image"].(string)
		}

		shareimage = shareImgUrlToFilename(shareimageurl)
		mainpages = append(mainpages, MainPage{id, title, shareimage})
	}

	return UsedData{Date: date, MainPages: mainpages}
}
开发者ID:kizure,项目名称:GO-ZhihuDaily,代码行数:31,代码来源:main.go

示例14: dir

// dir makes a good-faith attempt to return the directory
// portion of path. If path is empty, the result is ".".
// (Per the go/build package dependency tests, we cannot import
// path/filepath and simply use filepath.Dir.)
func dir(path string) string {
	if i := strings.LastIndexAny(path, `/\`); i > 0 {
		return path[:i]
	}
	// i <= 0
	return "."
}
开发者ID:tcard,项目名称:sgo,代码行数:11,代码来源:resolver.go

示例15: replaceWithToneMark

// replaceWithToneMark returns the UTF-8 representation of a pinyin syllable with
// the appropriate tone, e.g., dong1 => dōng, using the pinyin accent placement rules
func replaceWithToneMark(s string, tone int) (string, error) {
	lookup, err := toneLookupTable(tone)
	if err != nil {
		return "", err
	}

	if strings.Contains(s, "a") {
		return strings.Replace(s, "a", lookup["a"], -1), nil
	}
	if strings.Contains(s, "e") {
		return strings.Replace(s, "e", lookup["e"], -1), nil
	}
	if strings.Contains(s, "ou") {
		return strings.Replace(s, "o", lookup["o"], -1), nil
	}
	index := strings.LastIndexAny(s, "iüou")
	if index != -1 {
		var out bytes.Buffer
		for ind, runeValue := range s {
			if ind == index {
				out.WriteString(lookup[string(runeValue)])
			} else {
				out.WriteString(string(runeValue))
			}
		}
		return out.String(), nil
	}
	return "", fmt.Errorf("No tone match")
}
开发者ID:hermanschaaf,项目名称:cedict,代码行数:31,代码来源:cedict.go


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