Skip to content

Commit

Permalink
feat: string
Browse files Browse the repository at this point in the history
  • Loading branch information
Houserqu committed Mar 10, 2024
1 parent 1c01f44 commit d513e1e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions string/string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package string

import "strings"

/**
* 替换字符串中的最后一个匹配项
*/
func ReplaceLast(str, old, new string) string {
i := strings.LastIndex(str, old)
return str[:i] + strings.Replace(str[i:], old, new, 1)
}

0 comments on commit d513e1e

Please sign in to comment.