Pos返回needle在haystack中第一次出现的位置,区分大小写。 如果没有找到,则返回-1。 Pos(haystack, needle string, startOffset ...int) int
func ExamplePos() {
var (
haystack = `Hello World`
needle = `World`
result = gstr.Pos(haystack, needle)
)
fmt.Println(result)
// Output:
// 6
} PosRune的作用于函数Pos相似,但支持haystack和needle为unicode字符串。 PosRune(haystack, needle string, startOffset ...int) int
func ExamplePosRune() {
var (
haystack = `GoFrame是一款模块化、高性能、企业级的Go基础开发框架`
needle = `Go`
posI = gstr.PosRune(haystack, needle)
posR = gstr.PosRRune(haystack, needle)
)
fmt.Println(posI)
fmt.Println(posR)
// Output:
// 0
// 22
} PosI返回needle在haystack中第一次出现的位置,不区分大小写。 如果没有找到,则返回-1。 PosI(haystack, needle string, startOffset ...int) int
func ExamplePosI() {
var (
haystack = `goframe is very, very easy to use`
needle = `very`
posI = gstr.PosI(haystack, needle)
posR = gstr.PosR(haystack, needle)
)
fmt.Println(posI)
fmt.Println(posR)
// Output:
// 11
// 17
} PosRuneI的作用于函数PosI相似,但支持haystack和needle为unicode字符串。 PosIRune(haystack, needle string, startOffset ...int) int
func ExamplePosIRune() {
{
var (
haystack = `GoFrame是一款模块化、高性能、企业级的Go基础开发框架`
needle = `高性能`
startOffset = 10
result = gstr.PosIRune(haystack, needle, startOffset)
)
fmt.Println(result)
}
{
var (
haystack = `GoFrame是一款模块化、高性能、企业级的Go基础开发框架`
needle = `高性能`
startOffset = 30
result = gstr.PosIRune(haystack, needle, startOffset)
)
fmt.Println(result)
}
// Output:
// 14
// -1
} PosR返回needle在haystack中最后一次出现的位置,区分大小写。 如果没有找到,则返回-1。 PosR(haystack, needle string, startOffset ...int) int
func ExamplePosR() {
var (
haystack = `goframe is very, very easy to use`
needle = `very`
posI = gstr.PosI(haystack, needle)
posR = gstr.PosR(haystack, needle)
)
fmt.Println(posI)
fmt.Println(posR)
// Output:
// 11
// 17
} PosRuneR的作用于函数PosR相似,但支持haystack和needle为unicode字符串。 PosRRune(haystack, needle string, startOffset ...int) int
func ExamplePosRRune() {
var (
haystack = `GoFrame是一款模块化、高性能、企业级的Go基础开发框架`
needle = `Go`
posI = gstr.PosIRune(haystack, needle)
posR = gstr.PosRRune(haystack, needle)
)
fmt.Println(posI)
fmt.Println(posR)
// Output:
// 0
// 22
} PosRI返回needle在haystack中最后一次出现的位置,不区分大小写。 如果没有找到,则返回-1。 PosRI(haystack, needle string, startOffset ...int) int
func ExamplePosRI() {
var (
haystack = `goframe is very, very easy to use`
needle = `VERY`
posI = gstr.PosI(haystack, needle)
posR = gstr.PosRI(haystack, needle)
)
fmt.Println(posI)
fmt.Println(posR)
// Output:
// 11
// 17
} PosRIRune的作用于函数PosRI相似,但支持haystack和needle为unicode字符串。 PosRIRune(haystack, needle string, startOffset ...int) int
func ExamplePosRIRune() {
var (
haystack = `GoFrame是一款模块化、高性能、企业级的Go基础开发框架`
needle = `GO`
posI = gstr.PosIRune(haystack, needle)
posR = gstr.PosRIRune(haystack, needle)
)
fmt.Println(posI)
fmt.Println(posR)
// Output:
// 0
// 22
} 备案信息: 粤ICP备15087711号-2
Copyright © 2008-2024 啊嘎哇在线工具箱 All Rights.
本站所有资料来源于网络,版权归原作者所有,仅作学习交流使用,如不慎侵犯了您的权利,请联系我们。