Skip to content

startsWith - Check if a string starts with a given prefix

The startsWith function returns true if a given substring appears at the start 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

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

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

Arguments

NameTypeRequiredDescription
stringstringtrueThe full string to test i.e the haystack
prefixstringtrueThe prefix to check against the string i.e the needle

Example - Check if a string contains an IBM CRN

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 a given string is an IBM CRN, we can check if it begins with 'crn:'.

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

This will define a new boolean field indicating whether a given string is an IBM CRN.

Try it yourself

Open up your log explore screen and run the following command:

create email from 'chris@coralogix.com'
| create is_chris from email.startsWith('chris')
| choose email, is_chris