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
}
我们提供的服务有:网站建设、网站制作、微信公众号开发、网站优化、网站认证、肃州ssl等。为1000多家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的肃州网站制作公司
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
}
网站栏目:创新互联GoFrame教程:GoFramegstr-查找替换
网页链接:http://www.shufengxianlan.com/qtweb/news11/295611.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联