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

doc: add doc for Substring

This commit is contained in:
dudaodong
2022-12-29 20:03:59 +08:00
parent 1dc5e8ac23
commit 526e568d0e
4 changed files with 78 additions and 0 deletions

View File

@@ -550,6 +550,8 @@ import "github.com/duke-git/lancet/v2/strutil"
- **<big>SplitEx</big>** : split a given string which can control the result slice contains empty string or not.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#SplitEx)]
[[play](https://go.dev/play/p/Us-ySSbWh-3)]
- **<big>Substring</big>** : returns a substring of the specified length starting at the specified offset position.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#Substring)]
- **<big>Wrap</big>** : wrap a string with given string.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#Wrap)]
[[play](https://go.dev/play/p/KoZOlZDDt9y)]

View File

@@ -546,6 +546,8 @@ import "github.com/duke-git/lancet/v2/strutil"
- **<big>SplitEx</big>** : 拆分给定的字符串可以控制结果切片是否包含空字符串。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#SplitEx)]
[[play](https://go.dev/play/p/Us-ySSbWh-3)]
- **<big>Substring</big>** : 根据指定的位置和长度截取子字符串。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#Substring)]
- **<big>Wrap</big>** : 用给定字符包裹传入的字符串
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#Wrap)]
[[play](https://go.dev/play/p/KoZOlZDDt9y)]

View File

@@ -37,6 +37,7 @@ import (
- [SnakeCase](#SnakeCase)
- [UpperSnakeCase](#UpperSnakeCase)
- [SplitEx](#SplitEx)
- [Substring](#Substring)
- [Wrap](#Wrap)
- [Unwrap](#Unwrap)
@@ -631,6 +632,42 @@ func main() {
### <span id="Substring">Substring</span>
<p>Returns a substring of the specified length starting at the specified offset position.</p>
<b>Signature:</b>
```go
func Substring(s string, offset int, length uint) string
```
<b>Example:</b>
```go
import (
"fmt"
"github.com/duke-git/lancet/v2/strutil"
)
func main() {
result1 := strutil.Substring("abcde", 1, 3)
fmt.Println(result1) //bcd
result2 := strutil.Substring("abcde", 1, 5)
fmt.Println(result2) //bcde
result3 := strutil.Substring("abcde", -1, 3)
fmt.Println(result3) //e
result4 := strutil.Substring("abcde", -2, 2)
fmt.Println(result4) //de
result5 := strutil.Substring("abcde", -2, 3)
fmt.Println(result5) //de
result6 := strutil.Substring("你好,欢迎你", 0, 2)
fmt.Println(result6) //你好
}
```
### <span id="Wrap">Wrap</span>
<p>Wrap a string with given string.</p>

View File

@@ -37,6 +37,7 @@ import (
- [SnakeCase](#SnakeCase)
- [UpperSnakeCase](#UpperSnakeCase)
- [SplitEx](#SplitEx)
- [Substring](#Substring)
- [Wrap](#Wrap)
- [Unwrap](#Unwrap)
@@ -600,6 +601,42 @@ func main() {
}
```
### <span id="Substring">Substring</span>
<p>根据指定的位置和长度截取子字符串</p>
<b>函数签名:</b>
```go
func Substring(s string, offset int, length uint) string
```
<b>例子:</b>
```go
import (
"fmt"
"github.com/duke-git/lancet/v2/strutil"
)
func main() {
result1 := strutil.Substring("abcde", 1, 3)
fmt.Println(result1) //bcd
result2 := strutil.Substring("abcde", 1, 5)
fmt.Println(result2) //bcde
result3 := strutil.Substring("abcde", -1, 3)
fmt.Println(result3) //e
result4 := strutil.Substring("abcde", -2, 2)
fmt.Println(result4) //de
result5 := strutil.Substring("abcde", -2, 3)
fmt.Println(result5) //de
result6 := strutil.Substring("你好,欢迎你", 0, 2)
fmt.Println(result6) //你好
}
```
### <span id="Wrap">Wrap</span>