mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-07 14:12:28 +08:00
fix: fix issue #275
This commit is contained in:
@@ -535,15 +535,22 @@ func RemoveWhiteSpace(str string, repalceAll bool) string {
|
||||
|
||||
// SubInBetween return substring between the start and end position(excluded) of source string.
|
||||
func SubInBetween(str string, start string, end string) string {
|
||||
if _, after, ok := strings.Cut(str, start); ok {
|
||||
if before, _, ok := strings.Cut(after, end); ok {
|
||||
if _, after, ok := Cut(str, start); ok {
|
||||
if before, _, ok := Cut(after, end); ok {
|
||||
return before
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// Cut splits the string at the first occurrence of separator.
|
||||
func Cut(str, sep string) (before, after string, found bool) {
|
||||
if i := strings.Index(str, sep); i >= 0 {
|
||||
return str[:i], str[i+len(sep):], true
|
||||
}
|
||||
return str, "", false
|
||||
}
|
||||
|
||||
// HammingDistance calculates the Hamming distance between two strings.
|
||||
// The Hamming distance is the number of positions at which the corresponding symbols are different.
|
||||
// This func returns an error if the input strings are of unequal lengths.
|
||||
|
||||
Reference in New Issue
Block a user