Skip to content

String Functions

String functions allow manipulating, normalizing, trimming, and formatting character strings in locals.yml expressions and variables.yml validation conditions.


Function Signature Description
lower lower(string) Converts all characters to lowercase.
upper upper(string) Converts all characters to uppercase.
trim trim(string, [cutset]) Removes leading and trailing whitespace or specified characters.
trimprefix trimprefix(string, prefix) Removes the specified prefix if present.
trimsuffix trimsuffix(string, suffix) Removes the specified suffix if present.
startswith startswith(string, prefix) Returns true if the string starts with prefix.
endswith endswith(string, suffix) Returns true if the string ends with suffix.
replace replace(string, search, rep) Replaces all occurrences of a search pattern.
split split(separator, string) Splits a string into a list by separator.
join join(separator, list) Joins list elements into a single string.
format format(format, ...args) Formats a string using printf-style verbs (%s, %d, %j, %%).
substr substr(string, offset, len) Extracts a substring from an offset.

Converts all characters in a string to lowercase.

Ventana de terminal
testform functions --eval "lower('STAGING-APP')"
# => "staging-app"
locals.yml
locals:
canonical_env: "${lower(var.environment)}"

Converts all characters in a string to uppercase.

Ventana de terminal
testform functions --eval "upper('qa_suite')"
# => "QA_SUITE"

Removes leading and trailing whitespace. Optionally accepts a second argument specifying the character set to remove.

Ventana de terminal
testform functions --eval "trim(' hello world ')"
# => "hello world"
testform functions --eval "trim('---alert---', '-')"
# => "alert"

Removes the specified prefix from the beginning of the string if present.

Ventana de terminal
testform functions --eval "trimprefix('https://api.example.com', 'https://')"
# => "api.example.com"

Removes the specified suffix from the end of the string if present.

Ventana de terminal
testform functions --eval "trimsuffix('tests/runs/suite.run.feature', '.run.feature')"
# => "tests/runs/suite"

Returns true if the string begins with the indicated prefix. Useful for input variable validation.

variables.yml
variable:
api_endpoint:
type: string
validation:
condition: "${startswith(var.api_endpoint, 'https://')}"
error_message: "API URL must use the secure HTTPS protocol."

Returns true if the string ends with the indicated suffix.

variables.yml
variable:
spec_file:
type: string
validation:
condition: "${endswith(var.spec_file, '.case.feature')}"
error_message: "Specification file must end with .case.feature."

Replaces all occurrences of a search pattern with a replacement string.

Ventana de terminal
testform functions --eval "replace('192.168.1.1', '.', '-')"
# => "192-168-1-1"

Divides a string into a list of strings using the specified delimiter.

Ventana de terminal
testform functions --eval "split(',', 'smoke,regression,e2e')"
# => ["smoke", "regression", "e2e"]

Concatenates elements of a string list using a delimiter.

Ventana de terminal
testform functions --eval "join(' / ', ['Checkout', 'Payments', 'Card'])"
# => "Checkout / Payments / Card"

Formats a string using C / Terraform-style format specifiers:

  • %s: String substitution.
  • %d: Integer substitution.
  • %j: Serialized JSON substitution.
  • %%: Literal % escape.
Ventana de terminal
testform functions --eval "format('https://%s.example.com:%d/v1', 'api', 8080)"
# => "https://api.example.com:8080/v1"
locals.yml
locals:
service_url: "${format('https://%s.%s', var.subdomain, var.domain)}"

Extracts a substring of length len starting at offset. If offset is negative, it counts backwards from the end of the string.

Ventana de terminal
testform functions --eval "substr('20261025_release', 0, 8)"
# => "20261025"
testform functions --eval "substr('file.json', -4, 4)"
# => "json"