string.go 693 B

12345678910111213141516171819202122232425262728293031323334
  1. package util
  2. import "strings"
  3. // Title returns a string value with s[0] which has been convert into upper case that
  4. // there are not empty input text
  5. func Title(s string) string {
  6. if len(s) == 0 {
  7. return s
  8. }
  9. return strings.ToUpper(s[:1]) + s[1:]
  10. }
  11. // Untitle returns a string value with s[0] which has been convert into lower case that
  12. // there are not empty input text
  13. func Untitle(s string) string {
  14. if len(s) == 0 {
  15. return s
  16. }
  17. return strings.ToLower(s[:1]) + s[1:]
  18. }
  19. // Index returns the index where the item equal,it will return -1 if mismatched
  20. func Index(slice []string, item string) int {
  21. for i := range slice {
  22. if slice[i] == item {
  23. return i
  24. }
  25. }
  26. return -1
  27. }