2020-07-29 17:11:41 +08:00
|
|
|
package util
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
2021-02-26 16:11:47 +08:00
|
|
|
// Title returns a string value with s[0] which has been convert into upper case that
|
|
|
|
// there are not empty input text
|
2020-07-29 17:11:41 +08:00
|
|
|
func Title(s string) string {
|
|
|
|
if len(s) == 0 {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.ToUpper(s[:1]) + s[1:]
|
|
|
|
}
|
|
|
|
|
2021-02-26 16:11:47 +08:00
|
|
|
// Untitle returns a string value with s[0] which has been convert into lower case that
|
|
|
|
// there are not empty input text
|
2020-07-29 17:11:41 +08:00
|
|
|
func Untitle(s string) string {
|
|
|
|
if len(s) == 0 {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.ToLower(s[:1]) + s[1:]
|
|
|
|
}
|
2020-12-07 14:55:10 +08:00
|
|
|
|
2021-02-26 16:11:47 +08:00
|
|
|
// Index returns the index where the item equal,it will return -1 if mismatched
|
2020-12-07 14:55:10 +08:00
|
|
|
func Index(slice []string, item string) int {
|
2020-12-10 15:16:13 +08:00
|
|
|
for i := range slice {
|
2020-12-07 14:55:10 +08:00
|
|
|
if slice[i] == item {
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
2020-12-10 15:16:13 +08:00
|
|
|
|
2020-12-07 14:55:10 +08:00
|
|
|
return -1
|
|
|
|
}
|