Replace
返回origin
字符串中, search
被replace
替换后的新字符串。search
区分大小写。 Replace(origin, search, replace string, count ...int) string
func ExampleReplace() {
var (
origin = `golang is very nice!`
search = `golang`
replace = `goframe`
result = gstr.Replace(origin, search, replace)
)
fmt.Println(result)
// Output:
// goframe is very nice!
}
ReplaceI
返回origin
字符串中, search
被replace
替换后的新字符串。search
不区分大小写。 ReplaceI(origin, search, replace string, count ...int) string
func ExampleReplaceI() {
var (
origin = `golang is very nice!`
search = `GOLANG`
replace = `goframe`
result = gstr.ReplaceI(origin, search, replace)
)
fmt.Println(result)
// Output:
// goframe is very nice!
}
ReplaceByArray
返回origin
被一个切片按两个一组(search, replace)
顺序替换的新字符串,区分大小写。 ReplaceByArray(origin string, array []string) string
func ExampleReplaceByArray() {
{
var (
origin = `golang is very nice`
array = []string{"lang", "frame"}
result = gstr.ReplaceByArray(origin, array)
)
fmt.Println(result)
}
{
var (
origin = `golang is very good`
array = []string{"golang", "goframe", "good", "nice"}
result = gstr.ReplaceByArray(origin, array)
)
fmt.Println(result)
}
// Output:
// goframe is very nice
// goframe is very nice
}
ReplaceIByArray
返回origin
被一个切片按两个一组(search, replace)
顺序替换的新字符串,不区分大小写。 ReplaceIByArray(origin string, array []string) string
func ExampleReplaceIByArray() {
var (
origin = `golang is very Good`
array = []string{"Golang", "goframe", "GOOD", "nice"}
result = gstr.ReplaceIByArray(origin, array)
)
fmt.Println(result)
// Output:
// goframe is very nice
}
ReplaceByMap
返回origin
中map
的key
替换为value
的新字符串,区分大小写。 ReplaceByMap(origin string, replaces map[string]string) string
func ExampleReplaceByMap() {
{
var (
origin = `golang is very nice`
replaces = map[string]string{
"lang": "frame",
}
result = gstr.ReplaceByMap(origin, replaces)
)
fmt.Println(result)
}
{
var (
origin = `golang is very good`
replaces = map[string]string{
"golang": "goframe",
"good": "nice",
}
result = gstr.ReplaceByMap(origin, replaces)
)
fmt.Println(result)
}
// Output:
// goframe is very nice
// goframe is very nice
}
ReplaceIByMap
返回origin
中map
的key
替换为value
的新字符串,不区分大小写。 ReplaceIByMap(origin string, replaces map[string]string) string
func ExampleReplaceIByMap() {
var (
origin = `golang is very nice`
replaces = map[string]string{
"Lang": "frame",
}
result = gstr.ReplaceIByMap(origin, replaces)
)
fmt.Println(result)
// Output:
// goframe is very nice
}
备案信息: 粤ICP备15087711号-2
Copyright © 2008-2024 啊嘎哇在线工具箱 All Rights.
本站所有资料来源于网络,版权归原作者所有,仅作学习交流使用,如不慎侵犯了您的权利,请联系我们。