go TrimLeftFunc()

TrimLeftFunc()方法语法

func TrimLeftFunc(s string, f func(rune) bool) string

go源码对TrimLeftFunc()方法的介绍:

TrimLeftFunc returns a slice of the string s with all leading Unicode code points c satisfying f(c) removed.

即,golang的strings.TrimLeftFunc()方法,可以将字符串s左侧前缀的所有unicode编码值满足函数f的(返回true的)字符移除。该方法并不修改原字符串,以一个新的字符串进行返回。


strings.TrimLeftFunc()方法实例代码

func TrimUnicode(x rune) bool {
	if x == 97 {
		return true
	} else {
		return false
	}
}

func main() {
	var str string = strings.TrimLeftFunc("aaa笨鸟工具,x1y1z1.com", TrimUnicode)
	fmt.Println(str)
}

运行go文件,得到输出:

笨鸟工具,x1y1z1.com

全栈后端 / go语法 :













Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.