diff --git a/stringFunctions.go b/stringFunctions.go index 16bc013..b0190ae 100644 --- a/stringFunctions.go +++ b/stringFunctions.go @@ -9,12 +9,18 @@ Individual permissions beyond the scope of this license may be available at http **/ package ebkTools -import "math" +import ( + "math" + "strconv" +) // ShortenString() shortens String in them MIDDLE and inserts a surrogate. It ist possible to prevent shortening, if maximum stringlength is inside a tolerance space // fmt.Println(shortenString("abcdefghi",6,2,"[…]")) //a[…]hi func ShortenString(input string, lengthmax, tolerance int, surrogate string) (output string) { if len(input) > int(lengthmax+tolerance) && lengthmax != 0 { + if len(surrogate) == 0 { + surrogate = "[…]" //Set Default + } charstodelete := (float64(lengthmax) / 2) - (float64(len(surrogate)) / 2) front := input[0 : int(math.Floor(charstodelete))+1] @@ -26,3 +32,12 @@ func ShortenString(input string, lengthmax, tolerance int, surrogate string) (ou return } + +// Atoi() without Error, returning integer only +func Atoi(s string) int { + i, err := strconv.Atoi(s) + if err != nil { + panic(err) + } + return i +}