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

doc: add doc for Pad function

This commit is contained in:
dudaodong
2023-02-19 12:58:14 +08:00
parent 8784be1583
commit fee8d325b7
3 changed files with 119 additions and 1 deletions

View File

@@ -33,8 +33,9 @@ import (
- [UpperKebabCase](#UpperKebabCase)
- [LowerFirst](#LowerFirst)
- [UpperFirst](#UpperFirst)
- [PadEnd](#PadEnd)
- [Pad](#Pad)
- [PadStart](#PadStart)
- [PadEnd](#PadEnd)
- [Reverse](#Reverse)
- [SnakeCase](#SnakeCase)
- [UpperSnakeCase](#UpperSnakeCase)
@@ -449,6 +450,51 @@ func main() {
}
```
### <span id="Pad">Pad</span>
<p>Pads string on the left and right side if it's shorter than size.</p>
<b>Signature:</b>
```go
func Pad(source string, size int, padStr string) string
```
<b>Example:</b>
```go
import (
"fmt"
"github.com/duke-git/lancet/v2/strutil"
)
func main() {
result1 := strutil.Pad("foo", 1, "bar")
result2 := strutil.Pad("foo", 2, "bar")
result3 := strutil.Pad("foo", 3, "bar")
result4 := strutil.Pad("foo", 4, "bar")
result5 := strutil.Pad("foo", 5, "bar")
result6 := strutil.Pad("foo", 6, "bar")
result7 := strutil.Pad("foo", 7, "bar")
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
fmt.Println(result5)
fmt.Println(result6)
fmt.Println(result7)
// Output:
// foo
// foo
// foo
// foob
// bfoob
// bfooba
// bafooba
}
```
### <span id="PadEnd">PadEnd</span>
<p>Pads string on the right side if it's shorter than size.</p>

View File

@@ -449,6 +449,51 @@ func main() {
}
```
### <span id="Pad">Pad</span>
<p>如果字符串长度短于size则在左右两侧填充字符串。</p>
<b>函数签名:</b>
```go
func Pad(source string, size int, padStr string) string
```
<b>示例:</b>
```go
import (
"fmt"
"github.com/duke-git/lancet/v2/strutil"
)
func main() {
result1 := strutil.Pad("foo", 1, "bar")
result2 := strutil.Pad("foo", 2, "bar")
result3 := strutil.Pad("foo", 3, "bar")
result4 := strutil.Pad("foo", 4, "bar")
result5 := strutil.Pad("foo", 5, "bar")
result6 := strutil.Pad("foo", 6, "bar")
result7 := strutil.Pad("foo", 7, "bar")
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
fmt.Println(result5)
fmt.Println(result6)
fmt.Println(result7)
// Output:
// foo
// foo
// foo
// foob
// bfoob
// bfooba
// bafooba
}
```
### <span id="PadEnd">PadEnd</span>
<p>如果字符串长度短于size则在右侧填充字符串。</p>

View File

@@ -186,6 +186,33 @@ func ExampleUpperFirst() {
// Bar大
}
func ExamplePad() {
result1 := Pad("foo", 1, "bar")
result2 := Pad("foo", 2, "bar")
result3 := Pad("foo", 3, "bar")
result4 := Pad("foo", 4, "bar")
result5 := Pad("foo", 5, "bar")
result6 := Pad("foo", 6, "bar")
result7 := Pad("foo", 7, "bar")
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
fmt.Println(result5)
fmt.Println(result6)
fmt.Println(result7)
// Output:
// foo
// foo
// foo
// foob
// bfoob
// bfooba
// bafooba
}
func ExamplePadEnd() {
result1 := PadEnd("foo", 1, "bar")
result2 := PadEnd("foo", 2, "bar")