W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
Pos
?返回?needle
?在haystack中第一次出現(xiàn)的位置,區(qū)分大小寫(xiě)。 如果沒(méi)有找到,則返回-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
?的作用于函數(shù)?Pos
?相似,但支持?haystack
?和?needle
?為?unicode
?字符串。
PosRune(haystack, needle string, startOffset ...int) int
func ExamplePosRune() {
var (
haystack = `GoFrame是一款模塊化、高性能、企業(yè)級(jí)的Go基礎(chǔ)開(kāi)發(fā)框架`
needle = `Go`
posI = gstr.PosRune(haystack, needle)
posR = gstr.PosRRune(haystack, needle)
)
fmt.Println(posI)
fmt.Println(posR)
// Output:
// 0
// 22
}
PosI
?返回?needle
?在?haystack
?中第一次出現(xiàn)的位置,不區(qū)分大小寫(xiě)。 如果沒(méi)有找到,則返回?-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
?的作用于函數(shù)?PosI
?相似,但支持?haystack
?和?needle
?為?unicode
?字符串。
PosIRune(haystack, needle string, startOffset ...int) int
func ExamplePosIRune() {
{
var (
haystack = `GoFrame是一款模塊化、高性能、企業(yè)級(jí)的Go基礎(chǔ)開(kāi)發(fā)框架`
needle = `高性能`
startOffset = 10
result = gstr.PosIRune(haystack, needle, startOffset)
)
fmt.Println(result)
}
{
var (
haystack = `GoFrame是一款模塊化、高性能、企業(yè)級(jí)的Go基礎(chǔ)開(kāi)發(fā)框架`
needle = `高性能`
startOffset = 30
result = gstr.PosIRune(haystack, needle, startOffset)
)
fmt.Println(result)
}
// Output:
// 14
// -1
}
PosR
?返回?needle
?在?haystack
?中最后一次出現(xiàn)的位置,區(qū)分大小寫(xiě)。 如果沒(méi)有找到,則返回?-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
?的作用于函數(shù)?PosR
?相似,但支持?haystack
?和?needle
?為?unicode
?字符串。
PosRRune(haystack, needle string, startOffset ...int) int
func ExamplePosRRune() {
var (
haystack = `GoFrame是一款模塊化、高性能、企業(yè)級(jí)的Go基礎(chǔ)開(kāi)發(fā)框架`
needle = `Go`
posI = gstr.PosIRune(haystack, needle)
posR = gstr.PosRRune(haystack, needle)
)
fmt.Println(posI)
fmt.Println(posR)
// Output:
// 0
// 22
}
PosRI
?返回?needle
?在?haystack
?中最后一次出現(xiàn)的位置,不區(qū)分大小寫(xiě)。 如果沒(méi)有找到,則返回?-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
?的作用于函數(shù)?PosRI
?相似,但支持?haystack
?和?needle
?為?unicode
?字符串。
PosRIRune(haystack, needle string, startOffset ...int) int
func ExamplePosRIRune() {
var (
haystack = `GoFrame是一款模塊化、高性能、企業(yè)級(jí)的Go基礎(chǔ)開(kāi)發(fā)框架`
needle = `GO`
posI = gstr.PosIRune(haystack, needle)
posR = gstr.PosRIRune(haystack, needle)
)
fmt.Println(posI)
fmt.Println(posR)
// Output:
// 0
// 22
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: