sing/common/string.go
2022-08-15 22:36:45 +08:00

35 lines
643 B
Go

package common
import "strings"
func SubstringAfter(s string, substr string) string {
index := strings.Index(s, substr)
if index == -1 {
return s
}
return s[index+len(substr):]
}
func SubstringAfterLast(s string, substr string) string {
index := strings.LastIndex(s, substr)
if index == -1 {
return s
}
return s[index+len(substr):]
}
func SubstringBefore(s string, substr string) string {
index := strings.Index(s, substr)
if index == -1 {
return s
}
return s[:index]
}
func SubstringBeforeLast(s string, substr string) string {
index := strings.LastIndex(s, substr)
if index == -1 {
return s
}
return s[:index]
}