1
0
mirror of https://github.com/zu1k/nali.git synced 2025-01-23 21:59:02 +08:00
nali/internal/tools/replace.go

16 lines
370 B
Go
Raw Normal View History

2020-07-21 17:23:38 +08:00
package tools
2020-07-21 17:54:57 +08:00
import (
"strings"
)
2020-07-21 17:23:38 +08:00
2020-07-21 17:54:57 +08:00
func ReplaceAdd(origin string, old string, new string) (result string) {
2020-07-21 17:23:38 +08:00
subLen := len(new) - len(old)
wanted := old + strings.Repeat(" ", subLen)
if strings.Contains(origin, wanted) {
2020-07-21 17:54:57 +08:00
result = strings.ReplaceAll(origin, wanted, new)
2020-07-21 17:23:38 +08:00
}
2020-07-21 17:54:57 +08:00
result = strings.ReplaceAll(origin, old, new)
return strings.TrimRight(result, " \t")
2020-07-21 17:23:38 +08:00
}