• Infrastructure
    • terraform
    • packer
  • Networking
    • consul
  • Security
    • vault
    • boundary
  • Applications
    • nomad
    • waypoint
    • vagrant
  • HashiCorp Cloud Platform

    A fully managed platform to automate infrastructure on any cloud with HashiCorp products.

    • consul
    • terraform
    • vault
    • packerbeta
    Visit cloud.hashicorp.com
Sentinel
  • Intro
  • Docs
Download
    • v0.19.x (latest)
    • v0.18.x
    • v0.17.x
    • v0.16.x
    • v0.15.x
    • v0.14.x
    • v0.13.x
  • Release Notes
    • Overview
    • Policy as Code
    • Policy Language
    • Imports
    • Enforcement Levels
    • Overview
    • Override Files
    • Remote Sources
    • Overview
    • apply
    • fmt
    • test
    • Overview
    • Basics
    • Rules
    • Traces
    • Testing
    • Imports
    • Debugging
    • Overview
    • Modules
    • Plugins
    • Static Imports
    • Internals

    • Overview
    • Variables
    • Values
    • Lists
    • Maps
    • Rules
    • Imports
    • Parameters
    • Boolean Expressions
    • Arithmetic
    • Slices
    • Conditionals
    • Loops
    • Collection Operations
    • Functions
    • Scope
    • Undefined
    • Logging and Errors
    • Specification
    • Overview
    • append
    • delete
    • error
    • keys
    • length
    • print
    • range
    • values
    • Overview
    • base64
    • decimal
    • http
    • json
    • runtime
    • sockaddr
    • strings
    • time
    • types
    • units
    • version

  • Consul
  • Nomad
  • Terraform
  • Vault
Type '/' to Search

»Import: strings

The strings import exposes common string operations.

»strings.has_prefix(s, prefix)

Returns true if s starts with prefix.

strings.has_prefix("billing-id", "billing-") // true
strings.has_prefix("bill-id", "billing-")    // false

»strings.has_suffix(s, suffix)

Returns true if s ends with suffix.

strings.has_suffix("billing-id", "id")   // true
strings.has_suffix("billing-name", "id") // false

»strings.join(a, sep)

Joins a list with the string supplied by sep.

Multi-dimensional lists are supported, and non-string primitive types will be converted to their string equivalents. Maps and other complex non-list types are not supported.

strings.join(["foo", "bar", "baz"], ".")   // "foo.bar.baz"
strings.join([["foo", "bar"], "baz"], ".") // "foo.bar.baz"
strings.join(["a", 1, 1.01, true], ",")    // "a,1,1.01,true"

»strings.trim_prefix(s, prefix)

Trim the prefix from the string s. If the string doesn't have the prefix, then the string is returned unmodified.

strings.trim_prefix("billing-id", "billing-")   // "id"
strings.trim_prefix("bill-id",    "billing-")   // "bill-id"

»strings.trim_suffix(s, suffix)

Trim the suffix from the string s. If the string doesn't have the suffix, then the string is returned unmodified.

strings.trim_suffix("billing-id", "-id")    // "billing"
strings.trim_suffix("bill-id",    "-foo")   // "bill-id"

»strings.to_lower(s)

Lowercase the string s.

strings.to_lower("FoO") // "foo"

»strings.to_upper(s)

Uppercase the string s.

strings.to_upper("FoO") // "FOO"

»strings.split(s, sep)

Split the string 's' via a substring 'sep'. If 'sep' is not contained in 's', the return value will be a single-element list containing only 's'. As a special-case, if the input is already a list, it will be returned as-is. This allows calling the split function when not knowing if the input is already a list or not.

strings.split("foo,bar,baz", ",") // ["foo", "bar", "baz"]
strings.split(["foo", "bar", "baz"], ",") // ["foo", "bar", "baz"]
  • ProvisionMulti-Cloud Infrastructure
  • SecureMulti-Cloud Security
  • ConnectMulti-Cloud Networking
  • RunMulti-Cloud Orchestration
Products
  • Terraform
  • Vault
  • Consul
  • Nomad
  • Vagrant
  • Packer
  • Boundary NEW
  • Waypoint NEW
  • Sentinel
Resources
  • Blog
  • Tutorials
  • Community
  • Events
  • Integrations
  • Library
  • Partners
  • Podcast
  • Support
  • Training
Company
  • About Us
  • JobsWe're Hiring
  • Press Center
  • Brand
  • Contact Us
  • System Status
  • Cookie Manager
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
stdin: is not a tty