String
Library of functions for the string type.
Functions
Base64
Returns the base64 encoding of a string
String.Base64(string: string)
Parameters
string
: The string to encode as base64.
String.Base64("Hello World!")
CountSubString
Count the number of occurrences of a substring in a string.
String.CountSubString(string: string, substring: string)
Parameters
string
: The string on which the occurrences are counted.
substring
: The substring which is counted.
String.CountSubString("aXbX", "X") // 2
String.CountSubString("aXbX", "y") // 0
String.CountSubString("aXbX", "aX") // 1
Decode
Builds a string from a binary, given an encoding.
String.Decode(string: string, encoding: string)
Parameters
string
: The string to decode.
encoding
: The encoding that the binary value uses.
let
b = String.Encode("Hello world", "utf-8")
in
String.Decode(b, "utf-8") // "Hello world"
Empty
Returns true the string is empty.
String.Empty(string: string)
Parameters
string
: The string to check if empty.
String.Empty("") // true
String.Empty("Hello!") // false
"
Encode
Converts a string to a binary, given an encoding.
String.Encode(string: string, encoding: string)
Parameters
string
: The string to encode.
encoding
: The encoding to use.
String.EncodeString("Hello world", "utf-8")
From
Builds a string from a number, bool or temporal.
String.From(value: number or bool or temporal)
Parameters
value
: The value to convert to string.
String.From(123) // "123"
String.From(true) // "true"
String.From(Date.Build(1975, 6, 23)) // " 1975-06-23"
LTrim
Removes white space characters from the beginning of a string.
String.LTrim(string: string)
Parameters
string
: The string to be trimmed.
String.LTrim(" abc ") // "abc "
String.LTrim("abc ") // "abc "
String.LTrim(null) // null
Length
Compute the size of a string.
String.Length(string: string)
Parameters
string
: The string to compute the size.
String.Length("Hello John") // 10
LevenshteinDistance
Calculates the Levenshtein distance between two strings. The Levenshtein distance between two words is the minimum number of single-character edits (insertions, deletions or substitutions) required to change one word into the other.
String.LevenshteinDistance(string1: string, string2: string)
Parameters
string1
: The string from which the levenshtein distance is calculated.
string2
: The string to which the levenshtein distance is calculated.
String.LevenshteinDistance("Hello world", "Hello warld") // 1
String.LevenshteinDistance("Hello world", "Hello John") // 4
Lower
Convert a string to lowercase.
String.Lower(string: string)
Parameters
string
: The string to convert to lowercase.
lower("abC") // "abc"
lower(null) // null
RTrim
Removes white space characters from the end of a string.
String.RTrim(string: string)
Parameters
string
: The string to be trimmed.
String.RTrim(" abc ") // " abc"
String.RTrim(" abc") // " abc"
Read
Reads the contents of a location as a string.
String.Read(location: location)
Parameters
location
: The location to read.
ReadLines
Reads the contents of a location as lines of text
String.ReadLines(location: location, encoding: optional string)
Parameters
location
: The location to read lines from.
encoding
: Specifies the encoding of the data; if not specified defaults to utf-8.
String.ReadLines("http://somewhere/data.log") // ["line1", "line2", ...] "
Replace
Replace all matches of substring by a new string.
String.Replace(string: string, pattern: string, newSubString: string)
Parameters
string
: The string to be analyzed.
pattern
: The substring to match.
newSubString
: The new substring to replace matches with.
String.Replace("Hello John", "John", "Jane") // "Hello Jane"
String.Replace("Hello John", "o", "+") // "Hell+ J+hn!"
Replicate
Replicates a string by coping the substring for the specific number of repetitions.
String.Replicate(string: string, repetitions: int)
Parameters
string
: The string to replicate.
repetitions
: The number of repetitions.
String.Replicate("x", 4) // "xxxx"
String.Replicate("abc,", 2) // "abc,abc,"
Reverse
Reverses a string.
String.Reverse(string: string)
Parameters
string
: The string to reverse.
String.Reverse("1234") // "4321"
Split
Split a string into a list of strings given a separator.
String.Split(string: string, separator: string)
Parameters
string
: The string to split.
separator
: The separator by which the string is split.
String.Split("Value1||Value2", "||") // ["Value1","Value2"]
String.Split("Value1|Value2", "|") // ["Value1","Value2"]
StartsWith
Returns true if the beginning of a string matches a prefix.
String.StartsWith(string: string, prefix: string)
Parameters
string
: The string to find the prefix.
prefix
: The prefix to match.
String.StartsWith("Hello world", "Hello") // true
String.StartsWith("Hello world", "world") // false
"
SubString
Extract a substring from a string, given the start index and length of extraction. Index starts at 1. A negative number as the length means the remainder of the string.
String.SubString(string: string, index: int, size: int)
Parameters
string
: The string of which a substring is extracted.
index
: The start position to extract from.
size
: The size of the substring to extract.
String.SubString("Hello John", 4, 2) // "lo"
String.SubString("Hello John", 7, -1) // "John"
Trim
Removes white space characters from the beginning and end of a string.
String.Trim(string: string)
Parameters
string
: The string to be trimmed.
trim(" abc ") // "abc"
trim("abc ") // "abc"
Upper
Convert a string to uppercase.
String.Upper(string: string)
Parameters
string
: The string to convert to uppercase.
String.Upper("abC") // "ABC"
String.Upper(null) // null