-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstring.go
45 lines (41 loc) · 1002 Bytes
/
string.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
package godash
import (
"strings"
)
/*
*@Method: StringCapitalize
*@Description: Converts the first character of string to upper case and the remaining to lower case.
*@Param: 1.input string
*@Return: string
*/
func StringCapitalize(input string) string {
var output string
for index, item := range input {
if index == 0 {
output += strings.ToUpper(string(item))
} else {
output += strings.ToLower(string(item))
}
}
return output
}
/*
*@Method: StringEndsWith
*@Description: Checks if string ends with the given target string.
*@Param: 1.input string 2.target string
*@Return: bool
*/
func StringEndsWith(input, suffix string, end int) bool {
newString := string([]byte(input)[:len(input)-end])
return strings.HasSuffix(newString, suffix)
}
/*
*@Method: StringStartsWith
*@Description:
*@Param: 1.
*@Return:
*/
func StringStartsWith(input, prefix string, start int) bool {
newString := string([]byte(input)[start:])
return strings.HasPrefix(newString, prefix)
}