通用化推荐 一键开启舒适:
go get -u "github.com/jialanli/lacia/utils"
常用功能一应俱全, 非常实用。 调用:lacia.RemoveX(str, x) 参数2为指定的要去除的字符。
实例:
var x = `\`// 去除\fmt.Println(lacia.RemoveX("ab\\cde\\fg\\\\h\\",x)) // abcdefgh// 去除_fmt.Println(lacia.RemoveX("a_bcd__e_fgh_","_")) // abcdefgh// 去除*fmt.Println(lacia.RemoveX("*ab**cde***fgh","*")) // abcdefgh// (fmt.Println(lacia.RemoveX("a((bcde(fgh(","(")) // abcdefgh
空格也适用哦!其它操作示例:
如按多个指定字符分割字符串
fmt.Println(lacia.SplitByManyStrWith("a:b=c", []string{":", "="})) // [a b c]fmt.Println(lacia.SplitByManyStrWith("a:b=c:d", []string{":", "="})) // [a b c d]fmt.Println(lacia.SplitByManyStrWith("a+b=c-a", []string{"+", "-", "="})) // [a b c a]fmt.Println(lacia.SplitByManyStrWith("a/b-c&d_e%f$g", []string{"/", "-", "&", "_", "%", "$"})) // [a b c d e f g]
简单使人快乐!