Skip to content

endsWith - Check if a string ends with a given suffix

The endsWith function returns true if a given substring appears at the end of a string, and false if it does not.

NOTE: This is different from contains, which will check if a substring appears anywhere within a given string.

Syntax

endsWith(string: string, suffix: string): bool

Arguments

Name Type Required Description
string string true The string to test
suffix string true The suffix that will be tested against the end of the string

Example - Check if an IBM Cloud CRN refers to a known COS bucket

IBM Cloud CRNs look something like this: crn:v1:bluemix:public:cloud-object-storage:global:a/59bcbfa6ea2f006b4ed7094c1a08dcdd:1a0ec336-f391-4091-a6fb-5e084a4c56f4:bucket:mybucket

If we wish to check if this CDN refers to mybucket, we can check with endsWith

create is_my_bucket from endsWith(crn, 'mybucket')

This will define a new boolean field indicating whether a given CRN value ends with mybucket.

Another way to write this query is to check it directly against the crn field:

create is_my_bucket from crn.endsWith('mybucket')