Skip to content

Commit

Permalink
Add string.go
Browse files Browse the repository at this point in the history
  • Loading branch information
f0cii committed May 6, 2019
1 parent bfc246e commit ddb14c7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions strutil/string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package strutil

import "strings"

func PadRight(s string, padStr string, overallLen int) string {
var padCountInt = 1 + ((overallLen - len(padStr)) / len(padStr))
var retStr = s + strings.Repeat(padStr, padCountInt)
return retStr[:overallLen]
}

func PadLeft(s string, padStr string, overallLen int) string {
var padCountInt = 1 + ((overallLen - len(padStr)) / len(padStr))
var retStr = strings.Repeat(padStr, padCountInt) + s
return retStr[(len(retStr) - overallLen):]
}

func StringInSlice(list []string, a string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}

0 comments on commit ddb14c7

Please sign in to comment.