mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-11 16:22:26 +08:00
doc: add doc for Pad function
This commit is contained in:
@@ -33,8 +33,9 @@ import (
|
|||||||
- [UpperKebabCase](#UpperKebabCase)
|
- [UpperKebabCase](#UpperKebabCase)
|
||||||
- [LowerFirst](#LowerFirst)
|
- [LowerFirst](#LowerFirst)
|
||||||
- [UpperFirst](#UpperFirst)
|
- [UpperFirst](#UpperFirst)
|
||||||
- [PadEnd](#PadEnd)
|
- [Pad](#Pad)
|
||||||
- [PadStart](#PadStart)
|
- [PadStart](#PadStart)
|
||||||
|
- [PadEnd](#PadEnd)
|
||||||
- [Reverse](#Reverse)
|
- [Reverse](#Reverse)
|
||||||
- [SnakeCase](#SnakeCase)
|
- [SnakeCase](#SnakeCase)
|
||||||
- [UpperSnakeCase](#UpperSnakeCase)
|
- [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>
|
### <span id="PadEnd">PadEnd</span>
|
||||||
|
|
||||||
<p>Pads string on the right side if it's shorter than size.</p>
|
<p>Pads string on the right side if it's shorter than size.</p>
|
||||||
|
|||||||
@@ -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>
|
### <span id="PadEnd">PadEnd</span>
|
||||||
|
|
||||||
<p>如果字符串长度短于size,则在右侧填充字符串。</p>
|
<p>如果字符串长度短于size,则在右侧填充字符串。</p>
|
||||||
|
|||||||
@@ -186,6 +186,33 @@ func ExampleUpperFirst() {
|
|||||||
// Bar大
|
// 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() {
|
func ExamplePadEnd() {
|
||||||
result1 := PadEnd("foo", 1, "bar")
|
result1 := PadEnd("foo", 1, "bar")
|
||||||
result2 := PadEnd("foo", 2, "bar")
|
result2 := PadEnd("foo", 2, "bar")
|
||||||
|
|||||||
Reference in New Issue
Block a user