string functionsString functions available through the builtin object 'string`.
string.escapestring.appendstring.capitalizestring.capitalizewordsstring.containsstring.emptystring.whitespacestring.downcasestring.ends_withstring.equals_ignore_casestring.handleizestring.literalstring.lstripstring.pluralizestring.prependstring.removestring.remove_firststring.remove_laststring.replacestring.replace_firststring.rstripstring.sizestring.slicestring.slice1string.splitstring.starts_withstring.stripstring.strip_newlinesstring.to_intstring.to_longstring.to_floatstring.to_doublestring.truncatestring.truncatewordsstring.upcasestring.md5string.sha1string.sha256string.sha512string.hmac_sha1string.hmac_sha256string.hmac_sha512string.pad_leftstring.pad_rightstring.base64_encodestring.base64_decodestring.index_ofstring.escapestring.escape <text>
Escapes a string with escape characters.
text: The input stringThe two strings concatenated
input Try out
{{ "Hel\tlo\n\"W\\orld" | string.escape }}
output
Hel\tlo\n\"W\\orld
string.appendstring.append <text> <with>
Concatenates two strings
text: The input stringwith: The text to appendThe two strings concatenated
input Try out
{{ "Hello" | string.append " World" }}
output
Hello World
string.capitalizestring.capitalize <text>
Converts the first character of the passed string to a upper case character.
text: The input stringThe capitalized input string
input Try out
{{ "test" | string.capitalize }}
output
Test
string.capitalizewordsstring.capitalizewords <text>
Converts the first character of each word in the passed string to a upper case character.
text: The input stringThe capitalized input string
input Try out
{{ "This is easy" | string.capitalizewords }}
output
This Is Easy
string.containsstring.contains <text> <value>
Returns a boolean indicating whether the input string contains the specified string value.
text: The input stringvalue: The string to look forif text contains the string value
input Try out
{{ "This is easy" | string.contains "easy" }}
output
true
string.emptystring.empty <text>
Returns a boolean indicating whether the input string is an empty string.
text: The input stringif text is an empty string
input Try out
{{ "" | string.empty }}
output
true
string.whitespacestring.whitespace <text>
Returns a boolean indicating whether the input string is empty or contains only whitespace characters.
text: The input stringif text is empty string or contains only whitespace characters
input Try out
{{ "" | string.whitespace }}
output
true
string.downcasestring.downcase <text>
Converts the string to lower case.
text: The input stringThe input string lower case
input Try out
{{ "TeSt" | string.downcase }}
output
test
string.ends_withstring.ends_with <text> <value>
Returns a boolean indicating whether the input string ends with the specified string value.
text: The input stringvalue: The string to look forif text ends with the specified string value
input Try out
{{ "This is easy" | string.ends_with "easy" }}
output
true
string.equals_ignore_casestring.equals_ignore_case <text> <value>
Returns a boolean indicating whether the input string is equal to specified string 'value'. Comparison is case insensitive.
text: The input stringvalue: The string to compareif text is equal to string value, ignoring case
input Try out
{{ "Scriban" | string.equals_ignore_case "SCRIBAN" }}
output
true
string.handleizestring.handleize <text>
Returns a url handle from the input string.
text: The input stringA url handle
input Try out
{{ '100% M & Ms!!!' | string.handleize }}
output
100-m-ms
string.literalstring.literal <text>
Return a string literal enclosed with double quotes of the input string.
text: The string to return a literal from.The literal of a string.
If the input string has non printable characters or they need contain a double quote, they will be escaped.
input Try out
{{ 'Hello\n"World"' | string.literal }}
output
"Hello\n\"World\""
string.lstripstring.lstrip <text>
Removes any whitespace characters on the left side of the input string.
text: The input stringThe input string without any left whitespace characters
input Try out
{{ ' too many spaces' | string.lstrip }}
Highlight to see the empty spaces to the right of the string output
too many spaces
string.pluralizestring.pluralize <number> <singular> <plural>
Outputs the singular or plural version of a string based on the value of a number.
number: The number to checksingular: The singular string to return if number is == 1plural: The plural string to return if number is != 1The singular or plural string based on number
input Try out
{{ products.size }} {{products.size | string.pluralize 'product' 'products' }}
output
7 products
string.prependstring.prepend <text> <by>
Concatenates two strings by placing the by string in from of the text string
text: The input stringby: The string to prepend to textThe two strings concatenated
input Try out
{{ "World" | string.prepend "Hello " }}
output
Hello World
string.removestring.remove <text> <remove>
Removes all occurrences of a substring from a string.
text: The input stringremove: The substring to remove from the text stringThe input string with the all occurence of a substring removed
input Try out
{{ "Hello, world. Goodbye, world." | string.remove "world" }}
output
Hello, . Goodbye, .
string.remove_firststring.remove_first <text> <remove>
Removes the first occurrence of a substring from a string.
text: The input stringremove: The first occurence of substring to remove from the text stringThe input string with the first occurence of a substring removed
input Try out
{{ "Hello, world. Goodbye, world." | string.remove_first "world" }}
output
Hello, . Goodbye, world.
string.remove_laststring.remove_last <text> <remove>
Removes the last occurrence of a substring from a string.
text: The input stringremove: The last occurence of substring to remove from the text stringThe input string with the first occurence of a substring removed
input Try out
{{ "Hello, world. Goodbye, world." | string.remove_last "world" }}
output
Hello, world. Goodbye, .
string.replacestring.replace <text> <match> <replace>
Replaces all occurrences of a string with a substring.
text: The input stringmatch: The substring to find in the text stringreplace: The substring used to replace the string matched by match in the input textThe input string replaced
input Try out
{{ "Hello, world. Goodbye, world." | string.replace "world" "buddy" }}
output
Hello, buddy. Goodbye, buddy.
string.replace_firststring.replace_first <text> <match> <replace> <fromEnd: False>?
Replaces the first occurrence of a string with a substring.
text: The input stringmatch: The substring to find in the text stringreplace: The substring used to replace the string matched by match in the input textfromEnd: if true start match from endThe input string replaced
input Try out
{{ "Hello, world. Goodbye, world." | string.replace_first "world" "buddy" }}
output
Hello, buddy. Goodbye, world.
string.rstripstring.rstrip <text>
Removes any whitespace characters on the right side of the input string.
text: The input stringThe input string without any left whitespace characters
input Try out
{{ ' too many spaces ' | string.rstrip }}
Highlight to see the empty spaces to the right of the string output
too many spaces
string.sizestring.size <text>
Returns the number of characters from the input string
text: The input stringThe length of the input string
input Try out
{{ "test" | string.size }}
output
4
string.slicestring.slice <text> <start> <length>?
The slice returns a substring, starting at the specified index. An optional second parameter can be passed to specify the length of the substring. If no second parameter is given, a substring with the remaining characters will be returned.
text: The input stringstart: The starting index character where the slice should start from the input text stringlength: The number of character. Default is 0, meaning that the remaining of the string will be returned.The input string sliced
input Try out
{{ "hello" | string.slice 0 }}
{{ "hello" | string.slice 1 }}
{{ "hello" | string.slice 1 3 }}
{{ "hello" | string.slice 1 length:3 }}
output
hello
ello
ell
ell
string.slice1string.slice1 <text> <start> <length: 1>?
The slice returns a substring, starting at the specified index. An optional second parameter can be passed to specify the length of the substring. If no second parameter is given, a substring with the first character will be returned.
text: The input stringstart: The starting index character where the slice should start from the input text stringlength: The number of character. Default is 1, meaning that only the first character at start position will be returned.The input string sliced
input Try out
{{ "hello" | string.slice1 0 }}
{{ "hello" | string.slice1 1 }}
{{ "hello" | string.slice1 1 3 }}
{{ "hello" | string.slice1 1 length: 3 }}
output
h
e
ell
ell
string.splitstring.split <text> <match>
The split function takes on a substring as a parameter.
The substring is used as a delimiter to divide a string into an array. You can output different parts of an array using array functions.
text: The input stringmatch: The string used to split the input text stringAn enumeration of the substrings
input Try out
{{ for word in "Hi, how are you today?" | string.split ' ' ~}}
{{ word }}
{{ end ~}}
output
Hi,
how
are
you
today?
string.starts_withstring.starts_with <text> <value>
Returns a boolean indicating whether the input string starts with the specified string value.
text: The input stringvalue: The string to look forif text starts with the specified string value
input Try out
{{ "This is easy" | string.starts_with "This" }}
output
true
string.stripstring.strip <text>
Removes any whitespace characters on the left and right side of the input string.
text: The input stringThe input string without any left and right whitespace characters
input Try out
{{ ' too many spaces ' | string.strip }}
Highlight to see the empty spaces to the right of the string output
too many spaces
string.strip_newlinesstring.strip_newlines <text>
Removes any line breaks/newlines from a string.
text: The input stringThe input string without any breaks/newlines characters
input Try out
{{ "This is a string.\r\n With \nanother \rstring" | string.strip_newlines }}
output
This is a string. With another string
string.to_intstring.to_int <text>
Converts a string to an integer
text: The input stringA 32 bit integer or null if conversion failed
input Try out
{{ "123" | string.to_int + 1 }}
output
124
string.to_longstring.to_long <text>
Converts a string to a long 64 bit integer
text: The input stringA 64 bit integer or null if conversion failed
input Try out
{{ "123678912345678" | string.to_long + 1 }}
output
123678912345679
string.to_floatstring.to_float <text>
Converts a string to a float
text: The input stringA 32 bit float or null if conversion failed
input Try out
{{ "123.4" | string.to_float + 1 }}
output
124.4
string.to_doublestring.to_double <text>
Converts a string to a double
text: The input stringA 64 bit float or null if conversion failed
input Try out
{{ "123.4" | string.to_double + 1 }}
output
124.4
string.truncatestring.truncate <text> <length> <ellipsis>?
Truncates a string down to the number of characters passed as the first parameter. An ellipsis (...) is appended to the truncated string and is included in the character count
text: The input stringlength: The maximum length of the output string, including the length of the ellipsisellipsis: The ellipsis to append to the end of the truncated stringThe truncated input string
input Try out
{{ "The cat came back the very next day" | string.truncate 13 }}
output
The cat ca...
string.truncatewordsstring.truncatewords <text> <count> <ellipsis>?
Truncates a string down to the number of words passed as the first parameter. An ellipsis (...) is appended to the truncated string.
text: The input stringcount: The number of words to keep from the input text string before appending the ellipsisellipsis: The ellipsis to append to the end of the truncated stringThe truncated input string
input Try out
{{ "The cat came back the very next day" | string.truncatewords 4 }}
output
The cat came back...
string.upcasestring.upcase <text>
Converts the string to uppercase
text: The input stringThe input string upper case
input Try out
{{ "test" | string.upcase }}
output
TEST
string.md5string.md5 <text>
Computes the md5 hash of the input string
text: The input stringThe md5 hash of the input string
input Try out
{{ "test" | string.md5 }}
output
098f6bcd4621d373cade4e832627b4f6
string.sha1string.sha1 <text>
Computes the sha1 hash of the input string
text: The input stringThe sha1 hash of the input string
input Try out
{{ "test" | string.sha1 }}
output
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
string.sha256string.sha256 <text>
Computes the sha256 hash of the input string
text: The input stringThe sha256 hash of the input string
input Try out
{{ "test" | string.sha256 }}
output
9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
string.sha512string.sha512 <text>
Computes the sha512 hash of the input string
text: The input stringThe sha512 hash of the input string
input Try out
{{ "test" | string.sha512 }}
output
ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff
string.hmac_sha1string.hmac_sha1 <text> <secretKey>
Converts a string into a SHA-1 hash using a hash message authentication code (HMAC). Pass the secret key for the message as a parameter to the function.
text: The input stringsecretKey: The secret keyThe SHA-1 hash of the input string using a hash message authentication code (HMAC)
input Try out
{{ "test" | string.hmac_sha1 "secret" }}
output
1aa349585ed7ecbd3b9c486a30067e395ca4b356
string.hmac_sha256string.hmac_sha256 <text> <secretKey>
Converts a string into a SHA-256 hash using a hash message authentication code (HMAC). Pass the secret key for the message as a parameter to the function.
text: The input stringsecretKey: The secret keyThe SHA-256 hash of the input string using a hash message authentication code (HMAC)
input Try out
{{ "test" | string.hmac_sha256 "secret" }}
output
0329a06b62cd16b33eb6792be8c60b158d89a2ee3a876fce9a881ebb488c0914
string.hmac_sha512string.hmac_sha512 <text> <secretKey>
Converts a string into a SHA-512 hash using a hash message authentication code (HMAC). Pass the secret key for the message as a parameter to the function.
text: The input stringsecretKey: The secret keyThe SHA-512 hash of the input string using a hash message authentication code (HMAC)
input Try out
{{ "test" | string.hmac_sha512 "secret" }}
output
f8a4f0a209167bc192a1bffaa01ecdb09e06c57f96530d92ec9ccea0090d290e55071306d6b654f26ae0c8721f7e48a2d7130b881151f2cec8d61d941a6be88a
string.pad_leftstring.pad_left <text> <width>
Pads a string with leading spaces to a specified total length.
text: The input stringwidth: The number of characters in the resulting stringThe input string padded
input Try out
hello{{ "world" | string.pad_left 10 }}
output
hello world
string.pad_rightstring.pad_right <text> <width>
Pads a string with trailing spaces to a specified total length.
text: The input stringwidth: The number of characters in the resulting stringThe input string padded
input Try out
{{ "hello" | string.pad_right 10 }}world
output
hello world
string.base64_encodestring.base64_encode <text>
Encodes a string to its Base64 representation. Its character encoded will be UTF-8.
text: The string to encodeThe encoded string
input Try out
{{ "hello" | string.base64_encode }}
output
aGVsbG8=
string.base64_decodestring.base64_decode <text>
Decodes a Base64-encoded string to a byte array. The encoding of the bytes is assumed to be UTF-8.
text: The string to decodeThe decoded string
input Try out
{{ "aGVsbG8=" | string.base64_decode }}
output
hello
string.index_ofstring.index_of <text> <search> <startIndex>? <count>? <stringComparison>?
Reports the zero-based index of the first occurrence of the specified string in this instance. The search starts at a specified character position and examines a specified number of character positions.
text: The string to searchsearch: The string to find the index of.startIndex: If provided, the search starting position.
If , search will start at the beginning of .count: If provided, the number of character positions to examine.
If , all character positions will be considered.stringComparison: If provided, the comparison rules for the search.
If , Allowed values are one of the following:
'CurrentCulture', 'CurrentCultureIgnoreCase', 'InvariantCulture', 'InvariantCultureIgnoreCase', 'Ordinal', 'OrdinalIgnoreCase'The zero-based index position of the parameter from the start of if is found, or -1 if it is not. If value is , the return value is (if is not provided, the return value would be zero).
Note: This document was automatically generated from the source code using
Scriban.DocGen.