mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
feat: add ReplaceByMap
This commit is contained in:
1 parent
c86a8a479d
commit
f5784b0f46
3 files changed
+38
No files matched your search
@@ -445,3 +445,14 @@ func IndexOffset(str string, substr string, idxFrom int) int {
|
||||
|
||||
return strings.Index(str[idxFrom:], substr) + idxFrom
|
||||
}
|
||||
|
||||
// ReplaceByMap returns a copy of `origin`,
|
||||
// which is replaced by a map in unordered way, case-sensitively.
|
||||
// Play: todo
|
||||
func ReplaceByMap(str string, replaces map[string]string) string {
|
||||
for k, v := range replaces {
|
||||
str = strings.ReplaceAll(str, k, v)
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
Reference in new issue
Block a user