forked from samber/lo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_example_test.go
54 lines (47 loc) · 1.06 KB
/
string_example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package lo
import (
"fmt"
"math"
)
func ExampleSubstring() {
result1 := Substring("hello", 2, 3)
result2 := Substring("hello", -4, 3)
result3 := Substring("hello", -2, math.MaxUint)
result4 := Substring("🏠🐶🐱", 0, 2)
result5 := Substring("你好,世界", 0, 3)
fmt.Printf("%v\n", result1)
fmt.Printf("%v\n", result2)
fmt.Printf("%v\n", result3)
fmt.Printf("%v\n", result4)
fmt.Printf("%v\n", result5)
// Output:
// llo
// ell
// lo
// 🏠🐶
// 你好,
}
func ExampleChunkString() {
result1 := ChunkString("123456", 2)
result2 := ChunkString("1234567", 2)
result3 := ChunkString("", 2)
result4 := ChunkString("1", 2)
fmt.Printf("%v\n", result1)
fmt.Printf("%v\n", result2)
fmt.Printf("%v\n", result3)
fmt.Printf("%v\n", result4)
// Output:
// [12 34 56]
// [12 34 56 7]
// []
// [1]
}
func ExampleRuneLength() {
result1, chars1 := RuneLength("hellô"), len("hellô")
result2, chars2 := RuneLength("🤘"), len("🤘")
fmt.Printf("%v %v\n", result1, chars1)
fmt.Printf("%v %v\n", result2, chars2)
// Output:
// 5 6
// 1 4
}