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
|
|
|
}
|