Skip to content

Commit

Permalink
add SubStringByLen
Browse files Browse the repository at this point in the history
  • Loading branch information
xurwxj committed May 27, 2021
1 parent dae2017 commit 1ce4699
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions base/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,12 @@ func KeepRegexCharacter(str, regexStr string) (rs string, err error) {
rs = reg.ReplaceAllString(str, "")
return
}

// KeepRegexCharacter keep all character matched in regex
func SubStringByLen(str string, t int) (rs string) {
if str == "" {
return
}
rs = str[:t]
return
}
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import (
)

func main() {
dt()
dgt()
}

func dgt() {
s := base.SubStringByLen("ex v1.2.3 data", 5)
fmt.Println(s)
}

func dt() {
Expand Down

0 comments on commit 1ce4699

Please sign in to comment.