github.com/gogf/gf/v2@v2.7.4/text/gstr/gstr_array.go (about) 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 7 package gstr 8 9 // SearchArray searches string `s` in string slice `a` case-sensitively, 10 // returns its index in `a`. 11 // If `s` is not found in `a`, it returns -1. 12 func SearchArray(a []string, s string) int { 13 for i, v := range a { 14 if s == v { 15 return i 16 } 17 } 18 return NotFoundIndex 19 } 20 21 // InArray checks whether string `s` in slice `a`. 22 func InArray(a []string, s string) bool { 23 return SearchArray(a, s) != NotFoundIndex 24 } 25 26 // PrefixArray adds `prefix` string for each item of `array`. 27 // 28 // Example: 29 // PrefixArray(["a","b"], "gf_") -> ["gf_a", "gf_b"] 30 func PrefixArray(array []string, prefix string) { 31 for k, v := range array { 32 array[k] = prefix + v 33 } 34 }