~~~
form:="2,4,6,70"
sql :="2,4,6,9"
检查 form传来的数字 和sql匹配, 得出 sql变量是否有多余的数字, 比如以上
应该返回9, 因为form传来的数字,覆盖了SQL,而9被过滤出多余了 求代码 自己写了for好久没整好!
form:="2,4,55,70"
sql :="2,4,6,9"
如这种 就返回 6,9 被多余了
~~~
更多评论
````
package main
import (
"fmt"
"strings"
)
func main() {
form := "2,4,6,70"
sql := "2,4,6,9"
hash := make(map[string]bool)
formsz := strings.Split(form, ",")
for _, f := range formsz {
hash[f] = true
}
sqlsz := strings.Split(sql, ",")
re := ""
for _, s := range sqlsz {
if _, ok := hash[s]; !ok {
if re != "" {
re += ","
}
re += s
}
}
fmt.Println(re)
}
````
#3