gstr_array.go 852 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package gstr
  7. // SearchArray searches string `s` in string slice `a` case-sensitively,
  8. // returns its index in `a`.
  9. // If `s` is not found in `a`, it returns -1.
  10. func SearchArray(a []string, s string) int {
  11. for i, v := range a {
  12. if s == v {
  13. return i
  14. }
  15. }
  16. return NotFoundIndex
  17. }
  18. // InArray checks whether string `s` in slice `a`.
  19. func InArray(a []string, s string) bool {
  20. return SearchArray(a, s) != NotFoundIndex
  21. }
  22. // PrefixArray adds `prefix` string for each item of `array`.
  23. func PrefixArray(array []string, prefix string) {
  24. for k, v := range array {
  25. array[k] = prefix + v
  26. }
  27. }