|
|
@ -204,6 +204,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 |
|
|
@ -251,3 +271,27 @@ func UrlJoin(host, url string) string { |
|
|
|
|
|
|
|
return StringJoin(host, url) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 去除字符串的html标签 |
|
|
|
* @2021/10/20 |
|
|
|
*/ |
|
|
|
func TrimHtml(src string) string { |
|
|
|
//将HTML标签全转换成小写
|
|
|
|
re, _ := regexp.Compile("\\<[\\S\\s]+?\\>") |
|
|
|
src = re.ReplaceAllStringFunc(src, strings.ToLower) |
|
|
|
//去除STYLE
|
|
|
|
re, _ = regexp.Compile("\\<style[\\S\\s]+?\\</style\\>") |
|
|
|
src = re.ReplaceAllString(src, "") |
|
|
|
//去除SCRIPT
|
|
|
|
re, _ = regexp.Compile("\\<script[\\S\\s]+?\\</script\\>") |
|
|
|
src = re.ReplaceAllString(src, "") |
|
|
|
//去除所有尖括号内的HTML代码,并换成换行符
|
|
|
|
re, _ = regexp.Compile("\\<[\\S\\s]+?\\>") |
|
|
|
src = re.ReplaceAllString(src, "\n") |
|
|
|
//去除连续的换行符
|
|
|
|
re, _ = regexp.Compile("\\s{2,}") |
|
|
|
src = re.ReplaceAllString(src, "\n") |
|
|
|
return strings.TrimSpace(src) |
|
|
|
} |