Skip to content

endsWith

Description

Returns true if a string ends with a given substring, otherwise return false.

Note

Unlike contains, which checks for a substring anywhere in the string, endsWith only matches the end.

Syntax

Like many functions in DataPrime, endsWith supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

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

Arguments

NameTypeRequiredDescription
valuestringtrueThe string to test
suffixstringtrueThe substring to match against the end of the string

Example

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

IBM Cloud CRNs look like this:

crn:v1:bluemix:public:cloud-object-storage:global:a/59bcbfa6ea2f006b4ed7094c1a08dcdd:1a0ec336-f391-4091-a6fb-5e084a4c56f4:bucket:mybucket

To verify if the CRN points to mybucket, use endsWith:

create is_my_bucket from endsWith(crn, 'mybucket')
create is_my_bucket from crn.endsWith('mybucket')

Output

{
    "crn": "crn:v1:bluemix:public:cloud-object-storage:global:a/59bcbfa6ea2f006b4ed7094c1a08dcdd:1a0ec336-f391-4091-a6fb-5e084a4c56f4:bucket:mybucket",
    "is_my_bucket": true
}