本文整理汇总了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
}
示例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)
}
示例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]
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例10: hasExt
func hasExt(file string) bool {
i := strings.LastIndex(file, ".")
if i < 0 {
return false
}
return strings.LastIndexAny(file, `:\/`) < i
}
示例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)
}
示例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)))
}
}
示例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}
}
示例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 "."
}
示例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")
}