strutil能加个函数吗?判断str是否包含substring,substring可以是slice类型

This issue has been created since 2022-11-08.

strutil能加个函数吗?判断str是否包含substring,substring可以是slice类型
例如: strutil.contains("helloword",[]string{"hello", "world"});

gouserdev wrote this answer on 2022-11-10

func StringContainsOr(str string, substr []string) bool {
for k, v := range substr {
_ = k
if strings.Contains(str, v) {
return true
}
}
return false
}

func StringContainsAnd(str string, substr []string) bool {
for k, v := range substr {
_ = k
if !strings.Contains(str, v) {
return false
}
}
return true
}

gouserdev wrote this answer on 2022-11-10

我能contribute吗

inhere wrote this answer on 2022-11-10

可以的,欢迎!!带上单元测试就更棒了

我能contribute吗

inhere wrote this answer on 2022-11-10

搜了下,有这样的函数的:

https://github.com/gookit/goutil/blob/v0.5.15/strutil/check.go#L60

func HasOneSub(s string, subs []string) bool
func HasAllSubs(s string, subs []string) bool
More Details About Repo
Owner Name gookit
Repo Name goutil
Full Name gookit/goutil
Language Go
Created Date 2018-07-03
Updated Date 2023-03-22
Star Count 1263
Watcher Count 29
Fork Count 142
Issue Count 3

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Add extra field to AuthToken 1 2022-01-24 2023-02-07
pasting into settings password field actually pastes into composer 0 2022-05-13 2023-02-09
reference data for gtdb-Tk 1 2022-03-16 2023-03-20
Writing & Reading persons `vehicles` attributes from XML 9 2022-03-28 2023-02-15
Using sea-orm model as body type generates incorrect schema name 3 2023-01-13 2023-02-08
Songs Not playing after 2.0 1 2021-05-27 2023-02-10
Default /play service 1 2021-06-16 2022-11-04
Taxonomy Class should not use "name" to declare taxonomy ID. 1 2020-12-14 2023-02-18
[1.16.5] Crash at mod startup when Terra and Terraforged is on at same time 1 2021-08-27 2022-10-02
OSError: Socket is closed 1 2021-11-11 2023-02-10
Investigate tests run time 0 2022-02-03 2023-02-06
GitHub powered CMS 3 2021-12-03 2021-12-22
UpdateStats counts HEAD requests as GET requests 4 2021-06-29 2023-02-26
images not printing 0 2021-07-10 2022-01-14
Snyk vulnerability in v3.1.2 15 2021-04-29 2023-02-25
Get latest collected data for an instance based on timestamp? 0 2021-02-25 2023-02-25
Monster Hunter Rise Amiibo can't receive cosmetic equipment 2 2021-04-28 2023-02-26
Self signed certificate 4 2021-10-22 2023-01-12
Precompiled header makes custom-target-regenerated header trigger recompilation of all sources 0 2022-10-02 2023-02-15
[enterprise-4.9] Issue in file authentication/managing_cloud_provider_credentials/cco-mode-sts.adoc 2 2022-01-12 2023-02-04
About passing in elasticsearch_config argument for export_table_to_elasticsearch() method 0 2021-05-11 2023-01-14
Issues while saving a TorchScript Model(Anynet) using torch.jit.save() 0 2021-11-24 2023-02-10
Make the "Start the Bitwarden Desktop application" dialog a bit less "dramatic"? 4 2022-02-25 2023-02-17
Install at WSL 2 Win 10 6 2021-04-30 2023-02-01
Add Dogstatsd support 0 2021-10-07 2023-02-20
[Bug] Remove `blodId` from `htmlBody` in accordance with `RFC8621` documentation standard 0 2022-08-30 2023-03-08
"deken install" crashes on macOS 2 2019-10-24 2023-02-17
XcodeDeps Generator - Traits Support 1 2022-06-30 2023-01-29
【云学堂】开创数字化企业学习新时代 0 2021-11-03 2021-12-22
[bitnami/postgresql-ha]PostgreSQL standby POD is not coming UP 11 2021-09-10 2023-01-29
Add: Chamber of Representatives 0 2022-10-29 2023-02-03
[InstSimplify] FP-related miscompile 6 2022-09-28 2023-02-22
Secretive Agent not working 10 2022-07-21 2023-03-08
Conflict with Pure Paste 18 2022-07-12 2023-02-24
adapt-contrib-vanilla: font weight not defined for <strong> and <b> 2 2021-07-06 2022-07-15
[release-1.1]/[release-1.2] Prow GCR build is slow 2 2021-09-08 2023-02-25
Broken on the latest Ubuntu 20.04 LTS (Focal Fossa) 11 2020-05-01 2023-03-20
Space Debris (SCES-02290) does not boot 2 2021-08-04 2023-03-06
[QUERY] WithoutAccessFromAzureServices equivalent in Azure.ResourceManager.Sql 1 2023-03-02 2023-03-03
Specify the exact behavior for missing/null/empty value on a redeployment 0 2021-06-24 2023-01-09
[BUG] Resource Graph Query with new SDK 1 2023-03-01 2023-03-03
[Monitor Query] Migrate to data plane metrics query API 0 2023-03-02 2023-03-03
Expose `extensions` to plugin functions 0 2022-03-01 2023-02-17
queryConfigInfoByNamespace -BadSqlGrammarException 2 2022-03-10 2022-03-28
Add new album fails with error 409 "already exists" 7 2022-11-21 2023-03-17
Only `deg` is supported as an angular unit for hues 0 2022-06-30 2023-01-29
Why is channel not in ZeebeWorker initialization parameter? 2 2021-06-09 2023-03-08
improve the output format for RESTler bugs 3 2022-05-25 2023-02-09
proposal/new requirement - served filename in content-disposition header must follow correct encoding 2 2022-09-30 2023-02-17
MediaQuery.paddingOf does not rebuild when value changes 5 2022-12-11 2023-03-07