diff --git a/map.go b/map.go index 91434b9..6343157 100644 --- a/map.go +++ b/map.go @@ -119,3 +119,29 @@ func HttpBuildQuery(data map[string]string) string { return strings.Trim(query, "&") } + +/** + * 对map进行拼接 + * @param data map[string]string + * @2021/10/14 + * @wyy + */ +func HttpBuildStringQuery(data map[string]string) string { + + keySlice := []string{} + + for k, _ := range data { + keySlice = append(keySlice, k) + } + // sort.Strings(keySlice) //排序字符串 + + var query string + + for _, value := range keySlice { + if value != "" && data[value] != "" { + query += StringJoin(value, "=", data[value], "&") + } + } + + return strings.Trim(query, "&") +} diff --git a/string.go b/string.go index 49da990..b674a23 100755 --- a/string.go +++ b/string.go @@ -203,6 +203,26 @@ func IsInStringArray(arr []string, str string) bool { return isIn } +/** + * 字符串在字符切片中对应索引 + */ +func InStringArrayIndex(arr []string, str string) int { + // var isIn bool = false + length := len(arr) + if length < 1 { + return -1 + } + var index int = -1 + for k, item := range arr { + if item == str { + // isIn = true + index = k + break + } + } + return index +} + /* * 删除多余空格 * 2019/05/05