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.
Returns
string
: The base64 encoded string.
String.Base64("Hello World!")
// Result:
// "SGVsbG8gV29ybGQh"
Capitalize
Makes the first character of a string be uppercase and the rest lowercase.
String.Capitalize(string: string)
Parameters
string
: The string to be capitalized.
Returns
string
: The capitalized string.
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.
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.
String.Contains("Snapi", "api")
// Result:
// true
String.Contains("Snapi", "API")
// Result:
// false
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.
Returns
int
: The number of occurrences.
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.
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.
let
b = String.Encode("Hello world", "utf-8")
in
String.Decode(b, "utf-8")
// Result:
// "Hello world"
Empty
Returns true the string is empty.
String.Empty(string: string)
Parameters
string
: The string to check if empty.
Returns
bool
: True if the string is empty, false otherwise.
String.Empty("")
// Result:
// true
String.Empty("Hello!")
// Result:
// 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.
Returns
binary
: The encoded binary.
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.