Skip to main content

String

Library of functions for the string type.

Functions

Base64

Returns the base64 encoding of a string

Syntax:
String.Base64(string: string)
Parameters
  • string: The string to encode as base64.
Returns
  • string: The base64 encoded string.
Example:
String.Base64("Hello World!")
// Result:
// "SGVsbG8gV29ybGQh"

Capitalize

Makes the first character of a string be uppercase and the rest lowercase.

Syntax:
String.Capitalize(string: string)
Parameters
  • string: The string to be capitalized.
Returns
  • string: The capitalized string.
Example:
String.Capitalize("SNAPI")
// Result:
// "Snapi"

String.Capitalize("snapi")
// Result:
// "Snapi"

String.Capitalize("snAPI")
// Result:
// "Snapi"

String.Capitalize("Snapi")
// Result:
// "Snapi"

Contains

Returns true if a given string contains another given string.

Syntax:
String.Contains(s1: string, s2: string)
Parameters
  • s1: The input string to search within.

  • s2: The substring to search for within s1.

Returns
  • bool: True if s1 contains s2, false otherwise.
Example:
String.Contains("Snapi", "api")
// Result:
// true

String.Contains("Snapi", "API")
// Result:
// false

CountSubString

Count the number of occurrences of a substring in a string.

Syntax:
String.CountSubString(string: string, substring: string)
Parameters
  • string: The string on which the occurrences are counted.

  • substring: The substring which is counted.

Returns
  • int: The number of occurrences.
Example:
String.CountSubString("aXbX", "X")
// Result:
// 2

String.CountSubString("aXbX", "y")
// Result:
// 0

String.CountSubString("aXbX", "aX")
// Result:
// 1

Decode

Builds a string from a binary, given an encoding.

Syntax:
String.Decode(string: string, encoding: string)
Parameters
  • string: The string to decode.

  • encoding: The encoding that the binary value uses.

Returns
  • string: The decoded string.
Example:
let
b = String.Encode("Hello world", "utf-8")
in
String.Decode(b, "utf-8")
// Result:
// "Hello world"

Empty

Returns true the string is empty.

Syntax:
String.Empty(string: string)
Parameters
  • string: The string to check if empty.
Returns
  • bool: True if the string is empty, false otherwise.
Example:
String.Empty("")
// Result:
// true

String.Empty("Hello!")
// Result:
// false

Encode

Converts a string to a binary, given an encoding.

Syntax:
String.Encode(string: string, encoding: string)
Parameters
  • string: The string to encode.

  • encoding: The encoding to use.

Returns
  • binary: The encoded binary.
Example:
String.EncodeString("Hello world", "utf-8"))

From

Builds a string from a number, bool, temporal or location.

Syntax:
String.From(value: number or bool or temporal)
Parameters
  • value: The value to convert to string.
Returns
  • string: The string representation of the value.
Example:
String.From(123)
// Result:
// "123"

String.From(true)
// Result:
// "true"

String.From(Date.Build(1975, 6, 23))
// Result:
// "1975-06-23"

LTrim

Removes white space characters from the beginning of a string.

Syntax:
String.LTrim(string: string)
Parameters
  • string: The string to be trimmed.
Returns
  • string: The trimmed string.
Example:
String.LTrim("  abc ")
// Result:
// "abc"

String.LTrim("abc ")
// Result:
// "abc "

String.LTrim(null)
// Result:
// null

Length

Compute the size of a string.

Syntax:
String.Length(string: string)
Parameters
  • string: The string to compute the size.
Example:
String.Length("Hello John")
// Result:
// 10

LevenshteinDistance

Calculates the Levenshtein distance between two strings.

Syntax:
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.

Returns
  • int: The levenshtein distance between the two strings.
Example:
String.LevenshteinDistance("Hello world", "Hello warld")
// Result:
// 1

String.LevenshteinDistance("Hello world", "Hello John")
// Result:
// 4
note

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.

Lower

Convert a string to lowercase.

Syntax:
String.Lower(string: string)
Parameters
  • string: The string to convert to lowercase.
Returns
  • string: The converted string.
Example:
lower("abC")
// Result:
// "abc"

lower(null)
// Result:
// null

RTrim

Removes white space characters from the end of a string.

Syntax:
String.RTrim(string: string)
Parameters
  • string: The string to be trimmed.
Returns
  • string: The trimmed string.
Example:
String.RTrim("  abc ")
// Result:
// " abc"

String.RTrim(" abc")
// Result:
// " abc"

Read

Reads the contents of a location as a string.

Syntax:
String.Read(location: location)
Parameters
  • location: The location to read.
Returns
  • string: The contents of the location as a string.
Example:
String.Read("file:///tmp/test.txt")

ReadLines

Reads the contents of a location as lines of text

Syntax:
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.

Returns
  • collection(string): The lines of text in the location.
Example:
String.ReadLines("http://somewhere/data.log")"

Replace

Replace all matches of substring by a new string.

Syntax:
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.

Returns
  • string: The string with all matches replaced.
Example:
String.Replace("Hello John", "John", "Jane")
// Result:
// "Hello Jane"

String.Replace("Hello John", "o", "+")
// Result:
// "Hell+ J+hn!"

Replicate

Replicates a string by coping the substring for the specific number of repetitions.

Syntax:
String.Replicate(string: string, repetitions: int)
Parameters
  • string: The string to replicate.

  • repetitions: The number of repetitions.

Returns
  • string: The replicated string.
Example:
String.Replicate("x", 4)
// Result:
// "xxxx"

String.Replicate("abc,", 2)
// Result:
// "abc,abc,"

Reverse

Reverses a string.

Syntax:
String.Reverse(string: string)
Parameters
  • string: The string to reverse.
Returns
  • string: The reversed string.
Example:
String.Reverse("1234")
// Result:
// "4321"

Split

Split a string into a list of strings given a separator.

Syntax:
String.Split(string: string, separator: string)
Parameters
  • string: The string to split.

  • separator: The separator by which the string is split.

Returns
  • list(string): The list of strings.
Example:
String.Split("Value1||Value2", "||")
// Result:
// ["Value1","Value2"]

String.Split("Value1|Value2", "|")
// Result:
// ["Value1","Value2"]

StartsWith

Check if a string starts with a given prefix.

Syntax:
String.StartsWith(string: string, prefix: string)
Parameters
  • string: The string to find the prefix.

  • prefix: The prefix to match.

Returns
  • bool: True if the beginning of a string matches the prefix, false otherwise.
Example:
String.StartsWith("Hello world", "Hello")
// Result:
// true

String.StartsWith("Hello world", "world")
// Result:
// false

SubString

Extract a substring from a string, given the start index and length of extraction.

Syntax:
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.

Returns
  • string: The extracted substring.
Example:
String.SubString("Hello John", 4, 2)
// Result:
// "lo"

String.SubString("Hello John", 7, -1)
// Result:
// "John"
note

The index starts at 1. A negative number as the length means the remainder of the string.

Trim

Removes white space characters from the beginning and end of a string.

Syntax:
String.Trim(string: string)
Parameters
  • string: The string to be trimmed.
Returns
  • string: The trimmed string.
Example:
String.Trim("  abc ")
// Result:
// "abc"

String.Trim("abc ")
// Result:
// "abc"

Upper

Convert a string to uppercase.

Syntax:
String.Upper(string: string)
Parameters
  • string: The string to convert to uppercase.
Returns
  • string: The converted string.
Example:
String.Upper("abC") // "ABC"
// Result:
// "ABC"

String.Upper(null) // null
// Result:
// null