Browse Source

新增返回字符串在切片中对应索引和不进行排序map字典拼接

master
wuyongyuan 3 years ago
parent
commit
e4f8672814
2 changed files with 46 additions and 0 deletions
  1. +26
    -0
      map.go
  2. +20
    -0
      string.go

+ 26
- 0
map.go View File

@ -119,3 +119,29 @@ func HttpBuildQuery(data map[string]string) string {
return strings.Trim(query, "&") 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, "&")
}

+ 20
- 0
string.go View File

@ -203,6 +203,26 @@ func IsInStringArray(arr []string, str string) bool {
return isIn 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 * 2019/05/05


Loading…
Cancel
Save