Skip to content

startsWith

Description

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

Note

Unlike contains, which checks for a substring anywhere in the string, startsWith only matches the beginning.

Syntax

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

startsWith(value: string, prefix: string): bool
(value: string).startsWith(prefix: string): bool

Arguments

NameTypeRequiredDescription
valuestringtrueThe full string to test (haystack)
prefixstringtrueThe substring to check at the start of the string (needle)

Example

Check if a string is an IBM CRN

IBM Cloud CRNs look like this:

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

To confirm if a value is a CRN, check if it starts with crn::

create is_crn from startsWith(crn, 'crn:')
create is_crn from crn.startsWith('crn:')

Output

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