Skip to content

Commit

Permalink
Update add xstrings.Capitalize(s string) string
Browse files Browse the repository at this point in the history
  • Loading branch information
onanying committed Oct 17, 2023
1 parent 820485c commit 856e8b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ go get github.com/mix-go/xutil

## xstrings

| Function | Description |
|------------------------------------------------------------|----------------------------------------------------------------|
| xstrings.IsNumeric(s string) bool | Used to check if the variable is a number or a numeric string. |
| xstrings.SubString(s string, start int, length int) string | Return part of a string |
| Function | Description |
|------------------------------------------------------------|--------------------------------------------------------------------------|
| xstrings.IsNumeric(s string) bool | Used to check if the variable is a number or a numeric string. |
| xstrings.SubString(s string, start int, length int) string | Return part of a string |
| xstrings.Capitalize(s string) string | The function converts the first letter of the input string to uppercase. |

## xconv

Expand Down
13 changes: 12 additions & 1 deletion xstrings/strings.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package xstrings

import "strconv"
import (
"strconv"
"strings"
)

func IsNumeric(s string) bool {
_, err := strconv.ParseFloat(s, 64)
Expand All @@ -21,3 +24,11 @@ func SubString(s string, start int, length int) string {

return string(runes[start:end])
}

func Capitalize(s string) string {
if len(s) > 0 {
first := strings.ToUpper(s[:1]) // 将首字母转化为大写
return first + s[1:]
}
return s
}

0 comments on commit 856e8b2

Please sign in to comment.