Skip to content

Commit

Permalink
feat: some feat
Browse files Browse the repository at this point in the history
1. 字符判断是否为数字
  • Loading branch information
xingcxb committed Oct 31, 2023
1 parent 53a27f1 commit bb59ccd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions _examples/core/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ func TestLength(t *testing.T) {
fmt.Println(strKit.Length("👩‍👩‍👦‍👦"))
}

func TestIsNum(t *testing.T) {
fmt.Println(strKit.IsNum("123"))
fmt.Println(strKit.IsNum("123.123"))
fmt.Println(strKit.IsNum("123.123.123"))
}

func TestSplicing(t *testing.T) {
fmt.Println(strKit.Splicing("aa", "bb", "cc"))
}
Expand Down
10 changes: 10 additions & 0 deletions core/strKit/strKit.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ func Splicing(str ...string) string {
return newStr.String()
}

// IsNum 判断字符串是否为数字
/*
* @param s 字符串
* @return 返回是否为数字 true为数字;false为非数字
*/
func IsNum(s string) bool {
_, err := strconv.ParseFloat(s, 64)
return err == nil
}

// SubString 字符串截断
/**
* @param s 原始字符串
Expand Down

0 comments on commit bb59ccd

Please sign in to comment.