1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

feat: add FindAllOccurrences

This commit is contained in:
dudaodong
2025-01-10 14:03:45 +08:00
parent a0d97cf38e
commit 7653afa919
5 changed files with 119 additions and 7 deletions

View File

@@ -69,6 +69,7 @@ import (
- [TemplateReplace](#TemplateReplace)
- [RegexMatchAllGroups](#RegexMatchAllGroups)
- [ExtractContent](#ExtractContent)
- [FindAllOccurrences](#FindAllOccurrences)
<div STYLE="page-break-after: always;"></div>
@@ -1708,7 +1709,7 @@ func main() {
func RegexMatchAllGroups(pattern, str string) [][]string
```
<b>示例:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/JZiu0RXpgN-)</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/JZiu0RXpgN-)</span></b>
```go
import (
@@ -1741,7 +1742,7 @@ func main() {
func ExtractContent(s, start, end string) []string
```
<b>示例:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Ay9UIk7Rum9)</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Ay9UIk7Rum9)</span></b>
```go
import (
@@ -1759,4 +1760,32 @@ func main() {
// Output:
// [content1 content2 content1]
}
```
### <span id="FindAllOccurrences">FindAllOccurrences</span>
<p>返回子字符串在字符串中所有出现的位置。</p>
<b>函数签名:</b>
```go
func FindAllOccurrences(str, substr string) []int
```
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
```go
import (
"fmt"
"github.com/duke-git/lancet/v2/strutil"
)
func main() {
result := strutil.FindAllOccurrences("ababab", "ab")
fmt.Println(result)
// Output:
// [0 2 4]
}
```