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


Golang strings.LastIndexFunc函数代码示例

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


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

示例1: LastIndexFunc

// LastIndexFunc returns the index into s of the last Unicode code point
// satisfying f(c) or -1 if none do
func LastIndexFunc(s string, f func(rune) bool) int {
	function := func(c rune) bool {
		return unicode.Is(unicode.Han, c)
	}

	fmt.Println(strings.LastIndexFunc("hello 世界", function))    // 10 一个汉字貌似占3个位置
	fmt.Println(strings.LastIndexFunc("hello world", function)) // -1
	return strings.LastIndexFunc(s, f)
}
开发者ID:upccup,项目名称:cuplearn,代码行数:11,代码来源:stringsTest.go

示例2: Caller

// Caller report caller's position with file:function:line format
// depth means which caller, 0 means yourself, 1 means your caller
func Caller(depth int) string {
	_, file, line, _ := runtime.Caller(depth + 1)
	i := strings.LastIndexFunc(file, pathSepFunc)
	if i >= 0 {
		j := strings.LastIndexFunc(file[:i], pathSepFunc)
		if j >= 0 {
			i = j
		}
		file = file[i+1:]
	}
	return fmt.Sprintf("%s:%d", file, line)
}
开发者ID:sshitaime,项目名称:gohper,代码行数:14,代码来源:runtime.go

示例3: main

func main() {
	as := ""
	for _, char := range []rune{'A', 0xE6, 0346, 330, '\xE6', '\u00E6'} {
		fmt.Printf("[0x%x '%c']", char, char)
		as += string(char)
	}
	fmt.Println(as)
	line := "Θ£ 123 Θ £ £Θ" //Θ and £  not only one char
	i := strings.Index(line, " ")
	i2 := strings.IndexFunc(line, unicode.IsSpace)
	firstword := line[:i]
	j := strings.LastIndex(line, " ")
	j2 := strings.LastIndexFunc(line, unicode.IsSpace)
	lastword := line[j+1:]
	item, size := utf8.DecodeRuneInString(line[j+1:]) //返回第一个字符(可能超过一般的ascii码)和字节数
	fmt.Println(i, ",", i2, ",", firstword, ",", j, ",", j2, lastword, item, size)
	bs:="{\"error\":\"thumbnail's arg is out of range: 650001456812x\"}"
	i=strings.Index(bs,":")
	j=strings.LastIndex(bs,"}")
	fmt.Println(bs[i+2:j-1])
	

	var iss []int{1,2,3}
	fmt.Println()
}
开发者ID:needkane,项目名称:qiniu,代码行数:25,代码来源:testString.go

示例4: NewTurtleConfig

func NewTurtleConfig(syslogLog *syslog.Writer) (*TurtleConfig, error) {

	//DEBUG
	syslogLog.Notice("    [CONFIG] BEGIN.")

	cmdPath := os.Args[0]
	cmdPathLastSlash := strings.LastIndexFunc(cmdPath, func(c rune) bool {
		return '/' == c
	})

	cmdDirPath := cmdPath[0:cmdPathLastSlash]

	//DEBUG
	syslogLog.Notice(fmt.Sprintf("    [CONFIG] command path: [%v]", cmdPath))
	syslogLog.Notice(fmt.Sprintf("    [CONFIG] command path last slash: [%v]", cmdPathLastSlash))
	syslogLog.Notice(fmt.Sprintf("    [CONFIG] command dir path: [%v]", cmdDirPath))

	confRelativePath := "turtledq.ini"
	confPath := cmdDirPath + "/" + confRelativePath

	//DEBUG
	syslogLog.Notice(fmt.Sprintf("    [CONFIG] settings file relative path: [%v]", confRelativePath))
	syslogLog.Notice(fmt.Sprintf("    [CONFIG] settings file absolute path: [%v]", confPath))

	return NewTurtleConfigFromFile(syslogLog, confPath)
}
开发者ID:reiver,项目名称:turtledq,代码行数:26,代码来源:config.go

示例5: ParseTime

// ParseTime parses the time interval from s, and returns it
// as nanoseconds, if it is representable in seconds (with
// isNanoSeconds true), or sample count (with isNanoSeconds false)
// if not.
func ParseTime(s string) (t Time, err os.Error) {
	endi := strings.LastIndexFunc(s, isDigit) + 1
	if endi == 0 {
		return Time{}, os.NewError("invalid number")
	}
	number, suffix := s[0:endi], s[endi:]
	var mult int64
	switch suffix {
	case "s", "":
		mult = 1e9
	case "ms":
		mult = 1e6
	case "us":
		mult = 1e3
	case "ns":
		mult = 1
	case "x": // samples
		mult = 1
	}
	// use exact arithmetic if we can
	d, err := strconv.Atoi64(number)
	if err != nil {
		f, err := strconv.Atof64(number)
		if err != nil {
			return Time{}, err
		}
		d = int64(f * float64(mult))
	} else {
		d *= mult
	}
	return Time{d, suffix != "x"}, nil
}
开发者ID:zxpbenson,项目名称:rog-go,代码行数:36,代码来源:w_time.go

示例6: main

func main() {
	phrase := "naïve\u2028🚀"
	fmt.Printf("string: %s\n", phrase)
	fmt.Println("len:", len(phrase),
		"RuneCountInString:", utf8.RuneCountInString(phrase))
	fmt.Println("index rune     char bytes")
	for index, char := range phrase {
		fmt.Printf(" %2d   %-8U  %c    % X\n",
			index, char, char, []byte(string(char)))
	}
	last_rune, length := utf8.DecodeLastRuneInString(phrase)
	fmt.Printf("last rune: 0x%x length: %d\n", last_rune, length)
	fmt.Printf("length of string: %d length of []rune: %d\n",
		len(phrase), len([]rune(phrase)))
	fmt.Printf("line separator: %[1]U 0x%[1]x '%[1]c' %s\n", '\u2028', string('\u2028'))
	fmt.Printf("paragraph separator: %[1]U 0x%[1]x '%[1]c' %s\n", '\u2029', string('\u2029'))

	line := "rå tørt\u2028vær"
	i := strings.IndexFunc(line, unicode.IsSpace)
	firstWord := line[:i]
	j := strings.LastIndexFunc(line, unicode.IsSpace)
	_, size := utf8.DecodeRuneInString(line[j:])
	lastWord := line[j+size:]
	fmt.Println("size of space:", size)
	fmt.Println(firstWord, lastWord)
}
开发者ID:pto,项目名称:go-book,代码行数:26,代码来源:phrase.go

示例7: Word

// Word returns a string with the word of the view's internal buffer
// at the position corresponding to the point (x, y).
func (v *View) Word(x, y int) (string, error) {
	x, y, err := v.realPosition(x, y)
	if err != nil {
		return "", err
	}

	if x < 0 || y < 0 || y >= len(v.lines) || x >= len(v.lines[y]) {
		return "", errors.New("invalid point")
	}

	str := lineType(v.lines[y]).String()

	nl := strings.LastIndexFunc(str[:x], indexFunc)
	if nl == -1 {
		nl = 0
	} else {
		nl = nl + 1
	}
	nr := strings.IndexFunc(str[x:], indexFunc)
	if nr == -1 {
		nr = len(str)
	} else {
		nr = nr + x
	}
	return string(str[nl:nr]), nil
}
开发者ID:robert-butts,项目名称:slackterm,代码行数:28,代码来源:view.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: moveDotLeftWord

func moveDotLeftWord(ed *Editor) {
	if ed.dot == 0 {
		return
	}
	space := strings.LastIndexFunc(
		strings.TrimRightFunc(ed.line[:ed.dot], unicode.IsSpace),
		unicode.IsSpace) + 1
	ed.dot = space
}
开发者ID:yonglehou,项目名称:elvish,代码行数:9,代码来源:insert.go

示例10: killWordLeft

// NOTE(xiaq): A word is now defined as a series of non-whitespace chars.
func killWordLeft(ed *Editor) {
	if ed.dot == 0 {
	}
	space := strings.LastIndexFunc(
		strings.TrimRightFunc(ed.line[:ed.dot], unicode.IsSpace),
		unicode.IsSpace) + 1
	ed.line = ed.line[:space] + ed.line[ed.dot:]
	ed.dot = space
}
开发者ID:rathinaganesh,项目名称:elvish,代码行数:10,代码来源:builtins.go

示例11: lastWord

func lastWord(s string) string {

	idx := strings.LastIndexFunc(s, func(c rune) bool {
		return c >= 'A' && c <= 'Z'
	})
	if idx >= 0 {
		return s[idx:]
	}
	return ""
}
开发者ID:ttthzy,项目名称:qlang,代码行数:10,代码来源:interpret2.go

示例12: killWordLeft

// NOTE(xiaq): A word is now defined as a series of non-whitespace chars.
func killWordLeft(ed *Editor, k Key) *leReturn {
	if ed.dot == 0 {
		return nil
	}
	space := strings.LastIndexFunc(
		strings.TrimRightFunc(ed.line[:ed.dot], unicode.IsSpace),
		unicode.IsSpace) + 1
	ed.line = ed.line[:space] + ed.line[ed.dot:]
	ed.dot = space
	return nil
}
开发者ID:horryq,项目名称:elvish,代码行数:12,代码来源:builtins.go

示例13: TestIndexFunc

func TestIndexFunc(t *testing.T) {
	for _, tc := range indexFuncTests {
		first := strings.IndexFunc(tc.s, tc.f)
		if first != tc.first {
			t.Errorf("strings.IndexFunc(%q, %s) = %d; want %d", tc.s, tc.fname, first, tc.first)
		}
		last := strings.LastIndexFunc(tc.s, tc.f)
		if last != tc.last {
			t.Errorf("strings.LastIndexFunc(%q, %s) = %d; want %d", tc.s, tc.fname, last, tc.last)
		}
	}
}
开发者ID:skey,项目名称:go_examples,代码行数:12,代码来源:strings_test.go

示例14: stringSuffixIndexFunc

//  Returns the index i of the longest terminal substring s[i:] such that f
//  returns true for all runes in s[i:]. Returns -1 if there is no such i.
func stringSuffixIndexFunc(s string, f func(c rune) bool) (i int) {
	var hasSuffix bool
	i = strings.LastIndexFunc(s, func(c rune) (done bool) {
		if done = !f(c); !hasSuffix {
			hasSuffix = !done
		}
		return
	})
	if i++; !hasSuffix {
		i = -1
	}
	return
}
开发者ID:bmatsuo,项目名称:goline,代码行数:15,代码来源:strings.go

示例15: splitAtNumber

// splitAtNumber splits given string into prefix and numeric suffix.
// If no numeric suffix exists, full original string is returned as
// prefix with -1 as a suffix.
func splitAtNumber(str string) (string, int) {
	i := strings.LastIndexFunc(str, func(r rune) bool {
		return !unicode.IsDigit(r)
	}) + 1
	if i == len(str) {
		// no numeric suffix
		return str, -1
	}
	n, err := strconv.Atoi(str[i:])
	if err != nil {
		panic(fmt.Sprintf("parsing number %v: %v", str[i:], err)) // should never happen
	}
	return str[:i], n
}
开发者ID:imoapps,项目名称:juju,代码行数:17,代码来源:naturalsort.go


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