1 Star 0 Fork 28

cy1202/ha-api_1

forked from nyr/ha-api_1 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
utils.go 1.58 KB
一键复制 编辑 原始数据 按行查看 历史
liqiuyu 提交于 2022-04-20 14:21 . add file comments
/******************************************************************************
* Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
* ha-api is licensed under the Mulan PSL v2.
* You can use this software accodring to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: liqiuyu
* Date: 2022-04-19 16:49:51
* LastEditTime: 2022-04-20 11:32:56
* Description: 删除重复数据,获取数字单位
******************************************************************************/
package utils
import "regexp"
func IsInSlice(str string, sli []string) bool {
//TODO
for _, item := range sli {
if item == str {
return true
}
}
return false
}
// RemoveDupl remove duplicates in string array
func RemoveDupl(strs []string) []string {
strSet := map[string]bool{}
for _, v := range strs {
strSet[v] = true
}
strsDupl := []string{}
for k := range strSet {
strsDupl = append(strsDupl, k)
}
return strsDupl
}
// GetNumAndUnitFromStr gets the first number and the unit after this number
// like "20.5min" ==> ["20.5", "min"]
func GetNumAndUnitFromStr(s string) (string, string) {
r := regexp.MustCompile("[0-9](.*)[0-9]")
index := r.FindStringIndex(s)
if len(index) == 0 {
return s[:1], s[1:]
}
return s[:index[1]], s[index[1]:]
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chen1999122yan/ha-api_1.git
[email protected]:chen1999122yan/ha-api_1.git
chen1999122yan
ha-api_1
ha-api_1
master

搜索帮助