String

Index

All String functions

Name Function header Example Result Description Errorhandling
after func(value string, a string) string [[ $result := after "This is a test string" "is" ]] $result = “ a test string” Cuts the input string after the match/search string.
abbrev func(s string, width int) string [[ $result := abbrev "this is a very long test string" 10 ]] $result = “this is…” Cuts string and adds … if they are to long
abbrevBoth func(s string, left, right int) string [[ $resulat := abbrevBoth "this is a very long test string" 5 10 ]] $result = “…is a…” Cuts from left and right characters and replaces them with …, if string is large enough.
adler32sum func(input string) string [[ $result := adler32sum "This is a test string" ]] $result = “1363740589” Returns the adler32-hash of the source string.
camelcase func(str string) string [[ $result := camelcase "this is a TeSt String" ]] $result = “ThisIsATestString” Replaces a space or an underscores with a capital letter. Other capital letter will be replaced with lower case.
cat func(i interface…) string [[ $result := cat "This is a test string" "100" "This is a test string2" ]] $result = “This is a test string 100 This is a test string2” Concatenates strings together into 1 string
contains func(s string, substr string) bool [[ $result := contains "This is a test string" "is a" ]] $result = true Checks the string, if a specific search string occurs. If occurs = true, else = false
hasPrefix func(s string, prefix string) bool [[ $result := hasPrefix "This is a test string" "Thi" ]] $result = true Checks the string, if the string starts with the specified string.
hasSuffix func(s string, suffix string) bool [[ $result := hassuffix "This is a test string" "ing" ]] $result = true Checks the string, if the string ends with the specified string
indent func(v string, spaces int) string [[ $result := indent "This is a test string" 5 ]] $result = “ This is a test string” Indent the string based on the number with spaces.
initials func(s string) string [[ $result := initials "This is a test string" ]] $result = “Tiats” Contains all first letters from each word in the string.
join func(v interface{}, sep string) string [[ $result := join "This","is","a","test","string" "_" ]] $result = “This_is_a_test_string” Joins a list of strings into a single string, with the given separator.
kebabcase func(str string) string [[ $result := kebabcase "This is a TeSt String" ]] $result = “this-is-a-te-st-string” Replaces all spaces with a dash (-) and all upper case with a dash and the lower case character.
lower func(s string) string [[ $result := toLower "This is a TEST String" ]] $result = “this is a teststring” Converts all upper case characters to lower case
nindent func(v string, spaces int) string [[ $result := nindent "This is a test string" 2 ]] $result = “\n This is a test string” Is the same as the indent function, but prepends a new line to the beginning of the string.
noescape func(str string) HTML stdout: [[ noescape "<b>This is a test string</b>" ]] On standard Log console = stdout: This is a test string Doesn’t escape the string. Used for stdout/Console.
nospace func(str string) string [[ $result := toUpper "This is a test string" ]] $result = “Thisisateststring” Eliminiats all spaces in the string.
plural func(one string, many string, count int) string [[ $result := plural "This is a test string" "This are plenty of strings" 1 ]] $result = “This is a test string” Pluralize a string
quote func(i interface) string [[ $result := quote "This is a test string" "This is a test string2" ]] $result = “\“This is a test string\” \“This is a test string2\“” Inserts double quotes “ between strings.
randAlpha func(count int) string [[ $result := randAlpha "5" ]] $result = “KjcNd” Generates a random Alpha string with upper and lower case characters.
randAlphaNum func(count int) string [[ $result := randAlphaNum 10 ]] $result = “E9ZsAHervv” Contains random alpha and numeric characters
randAscii func(count int) string [[ $result := randAscii 5 ]] $result = “AmaN&” Generates a random Ascii string
randNumeric func(count int) string [[ $result := randNumeric 5 ]] $result = “67336” Generates a random numeric string.
repeat func(s string, count int) string [[ $result := repeat "This is a test string" 5 ]] $result = “This is a test stringThis is a test stringThis is a test stringThis is a test stringThis is a test string” Repeats the string based on the number.
replace func(src string, old string, new string) string [[ $result := replace "This is a test string" "string" "replace" ]] $result = “This is a test replace” Performs a simple string replacement.
replaceLine func(input, search, newline string) string [[ $result := replaceLine "This is a test string" "test" "String test new" ]] $result = “String test new” Replaces the source/input string, if a match with the search string occurs with the newline string.
replaceLineAndIndent func(input, search, newline string) string [[ $result := replaceLineAndIndent "This is a test string" "test" "String test new" ]] $result = “ String test new” replaces the source/input string, if a match with the search string occurs with the newline string and indent the line based on the source/input string.
sha1sum func(input string) string [[ $result := sha1sum "This is a test string" ]] $result = “e2f67c772368acdeee6a2242c535c6cc28d8e0ed” Returns the sha1-hash of the source string.
sha256sum func(input string) string [[ $result := sha256sum "This is a test string" ]] $result = “717ac506950da0ccb6404cdd5e7591f72018a20cbca27c8a423e9c9e5626ac61” Returns the sha256-hash of the source
shuffle func(str string) string [[ $result := shuffle "This is a test string" ]] $result = “ asnrttsesiThgsi it” Randomized order of same string
snakecase func(str string) string [[ $result := snakecase "This is a TeSt string" ]] $result = “this_is_a_te_st_string” Converts all upper to lower case and inserts additional an underscore “_”
sortAlpha func(list interface{}) []string [[ $result := sortAlpha [ "öäü","<",".","A","a","!","$","1" ] ]] $result = [ “!”,”\$“,”.“,“1”,”<“,“A”,“a”,“öäü” ] sorts a list of strings into alphabetical (lexicographical) order.
splitList func(orig string, sep string) []string [[ $result := splitList "This is a #test string" "#" ]] $result = “[“This is a “,“test string”]” Splits the source string based on separator and produces a array. [[ $result := splitList “This#is a #test string” “#” ]]
split func(orig string, sep string) []string [[ $result := split "This is a #test string" "#" ]] $result = “[“This is a “,“test string”]” Splits the source string based on separator and produces a array.
splitnToMap func(orig string, sep string, c int) map[string]string [[ $result := splitnToMap "This is a test string" "test" 2]] $result = “{”_0”:“This is a “,”_1”:” string”} Splits the source/orig string based on separator (sep) and the max split count ©, which produces a map with index keys.keys.
splitToMap func(orig string, sep string) map[string]string [[ $result := splitToMap "This is a test string" "test" ]] $result = “{”_0”:“This is a “,”_1”:” string”}” Splits the source string based on separator and produces a map with index keys.
squote func(i interface) string [[ $result := quote "This is a test string" "This is a test string2" ]] $result = “‘This is a test string’ ‘This is a test string2’” Inserts simple quotes ‘ between strings.
substr func(s string, start, end int) string [[ $result := substr "This is a test string" 1 11 ]] $result = “his is a t” “St” Cuts the string starting with start value end stop with the end value
swapcase func(str string) string [[ $result := swapcase "This is a tESt String" ]] $result = “tHIS IS A TesT sTRING” Changes lower case to upper and upper to lower case characters.
title func(s string) string [[ $result := title "this is a test string" ]] $result = “This Is A Test String” Converts the first letter of the word to upper case
toLower func(s string) string [[ $result := toLower "This is a TEST String" ]] $result = “this is a teststring” Converts all upper case characters to lower case
toString func(v interface{}) string [[ $result := toString "[This is a test1 string" "This is a TEST2 string]" ]] $result = “[This is a test1 string This is a TEST2 string]” Converts everything to a string.
toStrings func(v interface{}) []string [[ $result := toStrings "This is a test string" ]] $result = [ “This is a test string” ] Converts everything to a string array.
toUpper func(s string) string [[ $result := toUpper "This is a teststring" ]] $result = “ “THIS IS A TESTSTRING” Converts lower case charaters to upper case
trim func(s string) string [[ $result := trim " This is a teststring " ]] $result = “This is a teststring” Eliminates spaces at the beginning and end of a string
trimAll func(s string, cutset string) string [[ $result := trimAll "aabHabb" "ab" ]] $result = “H” Cuts characters from left and right, if any combination of cutset-characters matches.
trimPrefix / stripPrefix func(s string, prefix string) string [[ $result := trimPrefix "This is a test string" "This " ]] $result = “is a test string” Eliminates the characters from the beginning of the string.
trimSuffix / stripSuffix func(s string, suffix string) string [[ $result := trimSuffix "This is a test string" " string" ]] $result = “This is a test” Eliminates the suffix from the end of the string.
trunc func(s string, c int) string [[ $result := trunc "This is a test string" 11 ]] $result = “This is a t” Cuts from left to right depending on the integer value.
untitle func(s string) string [[ $result := title "This Is A Test String" ]] $result = “this is a test string” Converts the first letter of the word to lower case
upper func(s string) string [[ $result := toUpper "This is a teststring" ]] $result = “THIS IS A TESTSTRING” Converts lower case charaters to upper case
wrap func(str string, wrapLength int) string [[ $result := wrap "This is a test string" 10 ]] $result = “This is a\ntest\nstring” Replaces the space with a line breaks before the wrapLength has reached.
wrapWith func(str string, len int, sep string) string [[ $result := wrapWith "This is a test string" 10 "+#+" ]] $result = “This is a+#+test+#+string” Replaces space with the indiviual separator before the wrapLength has reached. It also splits long words.

abbrev

func(s string, width int) string

The abbrev function replaces all characters after width with …, if the string length is large enough. Otherwise it will present the whole string.

Application notes / Limits:

  • The string has to be at least 4 characters long to be truncated.

Examples

[[ $resulat := abbrev "this is a very long test string" 10 ]]
$result = "this is..."

[[ $result := abbrev "this is a very long test string" 2 ]]
$result = "this is a very long test string"

[[ $result := abbrev "thi" 2 ]]
$result = "thi"

[[ $result := abbrev "this is a very long test string" 100 ]]
$result = "this is a very long test string"

abbrevBoth

func (s string, left, right int) string

The abbrevBoth function replaces characters with … from left and right, if the string is large enough.

Logic:

  • Left should be greater 4, so left could be …
  • Right should be greater 7, so right could be …
  • … = 3 characters long. If only 3 characters are left, function will show the value
  • if the value is longer than 4, the function will replace the value with …

Application notes / Limits:

  • The string has to be at least 10 characters long, to get on both side …

Examples

[[ $resulat := abbrevBoth "this is a very long test string" 5 10 ]]
$result = "...is a..."

[[ $result := abbrevBoth "this is a very long test string" 0 10 ]]
$result = "this is..."

[[ $result := abbrevBoth "this is a very long test string" 4 6 ]]
$result = "this is a very long test string"

[[ $result := abbrevBoth "this is a very long test string" 5 7 ]]
$result = "...i..."

[[ $result := abbrevBoth "this is a very long test string" 10 23 ]]
$result = "...very long test st..."

[[ $result := abbrevBoth "this is a very long test string" 10 24 ]]
$result = "...very long test string"

shortest string for abbrevBoth
[[ $result := abbrevBoth "this is a " 5 7 ]]
$result = "...i..."

adler32sum

func(input string) string

The adler32sum function returns the adler32-hash of the source string. Wikipedia

Examples

[[ $result := adler32sum "This is a test string" ]]
$result = "1363740589"

[[ $result := adler32sum "This is a very long Test String with numbers 1,2,3,4,5 and special signs +*ç%&/()=?! and äöü:;" ]]
$result = "532b13b03e7bba6530090a8e7d6c2e909c8fbe2ee397eec6fb320cb7cfefdcb2"

after

func(value string, a string) string

The after function cuts the input string after the match/search string.

Examples

[[ $result := after "This is a test string" "test " ]]
$result = "string"

[[ $result := after "This is a test string" "is" ]]
$result = " a test string"

[[ $result := after "This is a test string" "is a " ]]
$result = "test string"

camelcase

func(str string) string

The camelcase function replaces a space or underscores with an upper case letter from the next letter and all other capital letters will be replaced to lower case character.

Application notes / Limits:

  • The first letter also is capitalized.
  • if there are multiple spaces or underscore between characters, the function replaces only the first occurence with the capital letter.

Examples

[[ $result := camelcase "This is a test string" ]]
$result = "ThisIsATestString"

[[ $result := camelcase "This is a TeSt String" ]]
$result = "ThisIsATestString"

[[ $result := camelcase "this is a TeSt String" ]]
$result = "ThisIsATestString"

[[ $result := camelcase "this:is___a  TeSt_String" ]]
$result = "This:is__A TestString"

cat

func(i interface...) string

The cat function concatenates multiple strings together into one, separating them with spaces.

Examples

[[ $result := cat "This is a test string" "100" "This is a test string2" ]]
$result = "This is a test string 100 This is a test string2"

contains

func(s string, substr string) bool

The contains function checks the string, if the specific substring/search occurs. If the string occurs, the function returns true otherwise false.

Examples

[[ $result := contains "This is a test string" "is a" ]]
$result = true

[[ $result := contains "This is a test string" "Aha" ]]
$result = false

hasPrefix

func(s string, prefix string) bool

The hasPrefix function checks the string, if the string starts with the specified string

Examples

[[ $result := hasPrefix "This is a test string" "Thi" ]]
$result = true

[[ $result := hasPrefix "This is a test string" "test" ]]
$result = false

hasSuffix

func(s string, suffix string) bool

The hasSuffix function checks the string, if the string ends with the specified string

Examples

[[ $result := hasSuffix "This is a test string" "ing" ]]
$result = true

[[ $result := hasSuffix "This is a test string" "test" ]]
$result = false

indent

func(v string, spaces int) string

The indent function indent the string based on the number with spaces.

Examples

[[ $result := indent "This is a test string" 5 ]]
$result = "     This is a test string"

initials

func(s string) string

The initials function contains all first letters from each word in the string.

Examples

[[ $result := initials "This is a test string" ]]
$result = "Tiats"

[[ $result := initials "This is a Test STRING" ]]
$result = "TiaTS"

join

func(v interface{}, sep string) string

The join function joins a list of strings into a single string, with the given separator.

Examples

[[ $result := join "This","is","a","test","string" "_" ]]
$result = "This_is_a_test_string"

[[ $result := join (list "This" "is" "a" "test" "string") "_" ]]
[[ setCurrentResultDataValue "DocuFixValue" $result ]]

kebabcase

func(str string) string

The kebabcase function replaces all spaces with a dash (-). Also all upper case letter will be replaces with an additional dash (-) and the upper case is replaced with the corresponding lower case letter.

with a dash (-)

All upper case characters will be converted to lower case.

Application notes / Limits:

  • if there are multiple spaces or underscore between characters, the function replaces all with a dash (-).
  • if multiple capital letters are together, the function inserts a dash in front of the first and last capital letter (see example 3 below)

Examples

[[ $result := kebabcase "This is a test string" ]]
$result = "this-is-a-test-string"

[[ $result := kebabcase "This is a TeSt String" ]]
$result = "this-is-a-te-st-string"

example 3: mulitple spaces, underscores and capital letters
[[ $result := kebabcase "This is___a  TESt String" ]]
$result = "this-is---a--te-st-string"

lower

check function: toLower

nindent

func(v string, spaces int) string

The nindent function is the same as the indent function, but prepends a new line to the beginning of the string.

Examples

[[ $result := nindent "This is  a--_test    String" 5 ]]
$result = "\n     This is  a--_test    String"

[[ $result := nindent "This is a test string" 2 ]]
$result = "\n  This is a test string"

noescape

func(str string) HTML

The noescape function doesn’t escape the string.

Application notes / Limits:

  • Used for generating output to the console/stanard out

Examples

stdout: [[ noescape "<b>This is a test string</b>" ]]
On standard Log console = stdout: <b>This is a test string</b>

nospace

func(str string) string

The nospace function eliminats all spaces in the string.

Examples

[[ $result := nospace "This is a test string" ]]
$result = "Thisisateststring"

plural

func(one string, many string, count int) string

The plural function pluralize a string. In the below, if the length of the string is 1, the first argument will be printed. Otherwise, the second argument will be printed.

The arguments are:

  • one/singular string
  • many/plural string
  • count/length integer

Examples

[[ $result := plural "This is a test string" "This are plenty of strings" 1 ]]
$result = "This is a test string"

[[ $result := plural "This is a test string" "This are plenty of strings" 2 ]]
$result = "This are plenty of strings"

quote

func(i interface) string

The quote function inserts double quotes “ between strings.

Examples

[[ $result := quote "This is a test string"  "This is a test string2" ]]
$result = "\"This is a test string\" \"This is a test string2\""

randAlpha

func(count int) string

The randAlpha function generates a random string only with Alpha characters with upper and lower case.

Examples

[[ $result := randAlpha 5 ]]
$result = "KjcNd"

randAlphaNum

func(count int) string

The randAlphaNum function generates a random string with numbers, upper and lower case characters.

Examples

[[ $result := randAlphaNum 10 ]]
$result = "E9ZsAHervv"

[[ $result := randAlphaNum 0 ]]
$result = ""

[[ $result := randAlphaNum "This is a test string" ]] 
$result = ""

[[ $result := randAlphaNum 20 ]] 
$result = "Q7OAP5Fn06dcuxwPpIIa"

randAscii

func(count int) string

The randAscii function generates a random Ascii string. Ascii see Wikipedia

Examples

[[ $result := randAscii 5 ]]
$result = "|maN&"

randNumeric

func(count int) string

The randNumeric function generates a random numeric string.

Examples

[[ $result := randNumeric 5 ]]
$result = "67336"

repeat

func(s string, count int) string

The repeat function repeats the string based on the number. The output is a string again.

Examples

[[ $result := repeat "This is a test string" 5 ]]
$result = "This is a test stringThis is a test stringThis is a test stringThis is a test stringThis is a test string"

[[ $result := repeat "This is a test string" 0 ]] 
$result = ""

replace

func(src string, old string, new string) string

The replace function performs a simple string replacement.

It takes three arguments:

  • string to replace
  • string to replace with
  • source string

Application notes / Limits:

  • If the replacing string part is identically to the source string, it will replaces the complete string.

Examples

[[ $result := replace "This is a test string" "string" "replace" ]]
$result = "This is a test replace"

[[ $result := replace "This is a Test string" "is a" "has been a"]]
$result = "This has been a test string"

replaceLine

func(input, search, newline string) string

The replaceLine function replaces the source/input string, if a match with the search string occurs with the newline string.

Examples

match
[[ $result := replaceLine "This is a test string" "test"  "String test new" ]]
$result = "String test new"

no match
[[ $result := replaceLine "This is a test string" "ab"  "String test new" ]]
$result = "This is a test string"

replaceLineAndIndent

func(input, search, newline string) string

The replaceLineAndIndent function replaces the source/input string, if a match with the search string occurs with the newline string and indent the line based on the source/input.

Examples

match
[[ $result := replaceLineAndIndent "   This is a test string" "test"  "String test new" ]]
$result = "   String test new"

no match
[[ $result := replaceLineAndIndent "This is a test string" "ab"  "String test new" ]]
$result = "This is a test string"

sha1sum

func(input string) string

The sha1sum function returns the sha1-hash of the source string.

Examples

[[ $result := sha1sum "This is a test string" ]]
$result = "e2f67c772368acdeee6a2242c535c6cc28d8e0ed"

[[ $result := sha1sum "This is a very long Test String with numbers 1,2,3,4,5 and special signs +*ç%&/()=?! and äöü:;" ]]
$result = "64fe0b4ff6bb7f3c1f863f8bf465f8e1cbdc2655"

sha256sum

func(input string) string

The sha256sum function returns the sha256-hash of the source string.

Examples

[[ $result := sha256sum "This is a test string" ]]
$result = "717ac506950da0ccb6404cdd5e7591f72018a20cbca27c8a423e9c9e5626ac61"

[[ $result := sha256sum "This is a very long Test String with numbers 1,2,3,4,5 and special signs +*ç%&/()=?! and äöü:;" ]]
$result = "532b13b03e7bba6530090a8e7d6c2e909c8fbe2ee397eec6fb320cb7cfefdcb2"

shuffle

func(str string) string

The shuffle function randomizes the input string, so the characters will be in another position in the output string. The amount of characters and length are equal.

Examples

[[ $result := shuffle "This is a test string" ]]
$result = " asnrttsesiThgsi   it"

[[ $result := shuffle "This is a test string 1 2 3 4 $ # xX" ]]
$result = "ti a t$r 14iXss 3 h # Tts2n xi   seg"

snakecase

func(str string) string

The snakecase function converts all upper to lower case and inserts additional an underscore “_“, if it’s not the first letter. Spaces also will be replaced with an underscore. See wikipedia

Examples

[[ $result := snakecase "This is a test string" ]]
$result = "this_is_a_test_string"

[[ $result := snakecase "This is a TeSt string" ]]
$result = "this_is_a_te_st_string"

[[ $result := snakecase "ThisisaTeStString" ]] 
$result = "thisisa_te_st_string"

[[ $result := snakecase "ThisisaTeStString" ]] 
$result = "thisisa_te_st_string12345_+(=?!$"

[[ $result := snakecase "GO-PATH" ]] 
$result = "go_path"

[[ $result := snakecase "GO PATH" ]] 
$result = "go_path"

[[ $result := snakecase "go-path" ]] 
$result = "go_path"

[[ $result := snakecase "GO-PATH" ]] 
$result = "go_path"

[[ $result := snakecase "GOPATH" ]] 
$result = "gopath"

sortAlpha

func(list interface{}) []string

The sortAlpha function sorts a list of strings into alphabetical (lexicographical) order.

Examples

[[ $result := sortAlpha (split "öäü,<,.,A,a,!,$,1" ",") ]]
$result =               [ "!","$",".","1","<","A","a","öäü" ]

with array
[[ $result := sortAlpha (list "öäü" "<" "." "A" "a" "!" "$" "1") ]]
$result =               [ "!","$",".","1","<","A","a","öäü" ]

[[ $result := sortAlpha (list "116" "100" "200" "99" "10") ]]
[[ $result =            [ "10","100","116","200",99" ]

[[ $result := sortAlpha (list "116" "100" "200" "099" "010") ]]
[[ $result =            [ "010","099","100","116","200" ]

split

see function splitList

splitList

func(orig string, sep string) []string

The splitList function splits the source string based on separator and produces a array.

Examples

[[ $result := splitList "This is a #test string" "#" ]]
$result = "["This is a ","test string"]"

[[ $result := splitList "This#is a test #string" "#" ]]
$result = "
[
"This",
"is a test ",
"string"
]
"

[[ $result := splitList "This#is a test string" "test" ]]
$result = "["This is a "," string"]"

splitToMap

func(orig string, sep string) map[string]string

The splitToMap function splits the source string based on separator and produces a map with index keys.

Examples

[[ $result := splitToMap "This is a test string" "test" ]]
$result = "{"_0":"This is a ","_1":" string"}"

[[ $result := splitToMap "This is a test string" "i" ]]
$result = "{"_0":"Th","_1":"s ","_2":"s a test str","_3":"ng"}"

splitnToMap

func(orig string, sep string, c int) map[string]string

The splitnToMap function splits the source/orig string based on separator (sep) and the max split count ©, which produces a map with index keys.

Application notes / Limits:

  • If the counter is smaller than the number of hits, all higher hits are indcluded in the last part.

Examples

[[ $result := splitnToMap "This is a test string" "test"  2]]
$result = "{"_0":"This a ","_1":" string"}"


[[ $result := splitnToMap "This is a test string" "t"  2]]
$result = "{"_0":"This is a ","_1":"est string"}"

[[ $result := splitnToMap "DEBUG  - 2021-11-08T11:48:16+01:00 - Sending heartbeat via discovery" " - " 3 ]]
$result = "{"_0":"DEBUG ","_1":"2021-11-08T11:48:16+01:00","_2":"Sending heartbeat via discovery"}"

squote

func(i interface) string

The squote function inserts simple quotes ‘ between strings.

Examples

[[ $result := squote "This is a test string"  "This is a test string2" ]]
$result = "'This is a test string' 'This is a test string2'"

stripPrefix

see function trimPrefix

stripSuffix

see function trimSufix

substr

func(s string, start, end int) string

The substr function cuts the string starting with start value end stop with the end value. Count starts for start end end value from the left side.

Application notes / Limits:

  • Value of start does not be greater or equal then the expected string length.
  • Value of the end could be larger then the expected string lenght.

Examples

[[ $result := substr "This is a test string" 1 11 ]]
$result = "his is a t"

[[ $result := substr "This is a test string" 0 11 ]]
$result = "This is a t"

[[ $result := substr "This is a test string" -1 11 ]]
$result = "This is a t"

[[ $result := substr "This is a test string" 10 30 ]]
$result = "test string"

[[ $result := substr "This is a test string" 21 30 ]]
$result = ""

swapcase

func(str string) string

The swapcase function changes lower to upper and upper to lower case characters.

Examples

[[ $result := swapcase "This is a test string" ]]
$result = "tHIS IS A TEST STRING"

[[ $result := swapcase "This is a test string 1 2 3 4 $ # xX" ]]
$result = "tHIS IS A TEST STRING 1 2 3 4 $ # Xx"

[[ $result := swapcase "This is a tESt String" ]]
$result = "tHIS IS A TesT sTRING"

title

func(s string) string

The title function converts the first letter of the word to upper case

Examples

[[ $result := title "this is a test string" ]]
$result = "This Is A Test String"

[[ $result := title "12345 -/^`()[] aAbBcC" ]]
$result = "12345 -/^`()[] AAbBcC"

[[ $result := title "this is a TEst STring öäü ÖÄÜ" ]] 
$result = "This Is A TEst STring Öäü ÖÄÜ"

toLower

The toLower function converts upper case characters to lower case.

Examples

[[ $result := toLower "This is a TEST String" ]]
$result = "this is a teststring"

[[ $result := toLower "12345öüätuotqrfASDFASFFADSF" ]]
$result = "AABBCCDD ÄÀÄÖÉÖÜÈÜ"

[[ $result := toLower "12345 -/^`()[] aAbBcC" ]] 
$result = "12345 -/^`()[] aabbcc"

toString

func(v interface{}) string

The toString function tries to convert everything to a string.

Examples

Object as string
[[ $data := newData ]]
[[ $data = addValue $data "object" "This is a testString" ]]
[[ $data = addValue $data "object" "This is a TEST2 string" ]]
[[ $result := toString $data ]]
$result = "map[object:[This is a testString This is a TEST2 string]]"

Integer to string
[[ $result := toString 116 ]]
$result = "116"

String
[[ $result := toString "This is a test string" ]]
$result = "This is a test string"

String-Array
[[ $result := toString (split "This,is,a,test,string" ",") ]]
$result = "[This is a test string]"

toStrings

func(v interface{}) []string

The toStrings function converts everything to a string array.

Examples

Object as string
[[ $data := newData ]]
[[ $data = addValue $data "object" "This is a testString" ]]
[[ $data = addValue $data "object" "aAbBcCdD" ]]
[[ $result := toStrings $data ]]
$result = [ "map[object:[This is a testString aAbBcCdD]]" ]

Integer to string
[[ $result := toStrings 116 ]]
$result = [ "116" ]

String
[[ $result := toStrings "This is a test string" ]]
$result = [ "This is a test string" ]

String-Array
[[ $result := toStrings (split "This,is,a,test,string" ",") ]]
$result = 
[
"This",
"is",
"a",
"test",
"string"
]

toUpper

func(s string) string

The toUpper function converts lower case characters to upper case.

Examples

[[ $result := toUpper "This is a teststring" ]]
$result = "THIS IS A TESTSTRING"

[[ $result := toUpper "aAbBcCdD äàÄöéÖüèÜ" ]]
$result = "AABBCCDD ÄÀÄÖÉÖÜÈÜ"

[[ $result := toUpper "12345 -/^`()[] aAbBcC" ]] 
$result = "12345 -/^`()[] AABBCC"

trim

func(s string) string

The trim function cuts spaces from left and right side of the string. If the string contains spaces inside the string itself, it doesn’t cut the spaces. See second example below.

Examples

start and end: no spaces
[[ $result := trim "This is a test string" ]]
$result = "This is a test string"

left and right spaces
[[ $result := trim "  This is a test string  " ]]
$result = "This is a test string"

left spaces
[[ $result := trim "  This is a test string" ]]
$result = "This is a test string"

right spaces
[[ $result := trim "This is a test string  " ]]
$result = "This is a test string"

trimAll

func(s string, cutset string) string

The trimAll function cuts the string from left and right, if any combination of cutset-characters matches.

Examples

[[ $result := trimAll "aabHabb" "ab" ]]
$result = "H"

[[ $result := trimAll "aabHabb" "abc" ]]
$result = "H"

[[ $result := trimAll "aabHabb" "bc" ]]
$result = "aabHa"

[[ $result := trimAll "     This is a test string" "ringTh " ]]
$result = "s is a test st"

trimPrefix

func(s string, prefix string) string

The trimPrefix function eliminates the the characters from the beginning of the string. If string doesn’t match, it returns the original string.

Examples

[[ $result := trimPrefix "This is a test string" "This " ]]
$result = "is a test string"

[[ $result := trimPrefix "This is a test string" "test" ]]
$result = "This is a test string"

trimSuffix

func(s string, suffix string) string

The trimSuffix function eliminates the suffix from the end of the string. If string doesn’t match, it returns the original string.

Examples

[[ $result := trimSuffix "This is a test string" " string" ]]
$result = "This is a test"

no match at the end, so you receive the original string
[[ $result := trimSuffix "This is a test string" "test"  ]]
$result = "This is a test string"

trunc

func(s string, c int) string

The trunc function cuts from left to right depending on the integer value.

Examples

[[ $result := trunc "This is a test string" 1 ]]
$result = "T"

[[ $result := trunc "This is a test string" 11 ]]
$result = "This is a t"

[[ $result := trunc "This is a test string with 12345 öÖéäÄàüÜè" 100 ]]
$result = "This is a test string with 12345 öÖéäÄàüÜè"

untitle

func(s string) string

The untitle function converts the first letter of the word to lower case

Examples

[[ $result := untitle "This Is A Test String" ]]
$result = "this is a test string"

[[ $result := untitle "12345 -/^`()[] AaBbCc" ]]
$result = "12345 -/^`()[] aaBbCc"

[[ $result := untitle "this is a TEst STring öäü ÖÄÜ" ]] 
$result = "this is a tEst sTring öäü öÄÜ"

upper

check function: toUpper

wrap

func(str string, wrapLength int) string

The wrap function replaces the space with a line breaks before the wrapLength has reached. If the text is much longer than the wrapLenght, the function will insert multiple line breaks/new lines.

Application notes / Limits:

  • If the word is longer than the wrapLenght, the function won’t insert a linebreak inside the long word.
  • If the wrapLength is longer than the string, the function won’t do anything

Examples

[[ $result := wrap "This is a test string" 10 ]]
                    12345678901234567890
										         ^         ^
														 |     v---|
$result =          "This is a\ntest\nstring"

[[ $result := wrap "This is a test string" 7 ]]
$result = "This is\na test\nstring"

[[ $result := wrap "This is a test string" 100 ]]
$result = "This is a test string"

wrapWith

func(str string, len int, sep string) string

The wrapWith function replaces space with the indiviual separator before the wrapLength has reached. It also splits long words. |

Examples

[[ $result := wrapWith "This is a test string" 10 "+#+" ]]
$result = "This is a+#+test+#+string"

[[ $result := wrapWith "This is a test string superBlubberLongDummyText" 10 "+#" ]]
$result = "This is a+#test+#string+#superBlubb+#erLongDumm+#yText"

[[ $result := wrapWith "This is a test string" 100 ]]
$result = "This is a test string"