-
Notifications
You must be signed in to change notification settings - Fork 9
/
text.go
80 lines (68 loc) · 1.53 KB
/
text.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package toolkit
import (
"fmt"
"strings"
)
var _randChars string
/*
func randChars() string {
if len(_randChars) == 0 {
alphabets := "abcdefghijklmnopqrstuvwxyz"
alphabetsCap := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
numerics := "0123456789"
whitespaces := "!@$&"
_randChars = alphabets + numerics + alphabetsCap + whitespaces
}
return _randChars
}
func SetRandChars(chars string) string {
_randChars = chars
return _randChars
}
*/
func RandomString(length int) string {
return GenerateRandomString("", length)
}
func Sprintf(pattern string, parms ...interface{}) string {
return fmt.Sprintf(pattern, parms...)
}
func Formatf(pattern string, parms ...interface{}) string {
r := pattern
for i, v := range parms {
r = strings.Replace(r, Sprintf("{%d}", i), v.(string), -1)
}
return r
}
func Printf(pattern string, parms ...interface{}) {
fmt.Printf(pattern, parms...)
}
func Printfn(pattern string, parms ...interface{}) {
fmt.Println(fmt.Sprintf(pattern, parms...))
}
func Println(s ...interface{}) {
fmt.Println(s...)
}
func Split(txt string, splitterChars []string) (splitValues []string,
splitters []string) {
txtLen := len(txt)
tmp := ""
for i := 0; i < txtLen; i++ {
c := string(txt[i])
if !HasMember(splitterChars, c) {
tmp += c
} else {
splitValues = append(splitValues, tmp)
splitters = append(splitters, c)
tmp = ""
}
}
return
}
func TrimByString(text, groupOfChar string) string {
return strings.Map(func(r rune) rune {
if strings.IndexRune(groupOfChar, r) < 0 {
return r
}
return -1
}, text)
}