Starts-with test

Learn how to check if a string starts with a specific prefix.

This test checks if a string begins with another string.

A string starts with another string if the latter is a prefix of the former. For example, "Hello world" starts with "Hello".

The test is case-sensitive, meaning that the strings must match exactly, including the case of the letters.

Croct's mascot neutral
Empty strings are everywhere!

An empty string is a prefix of every string. It follows a math concept called vacuous truth, which says that an empty set is a part of every set.

Syntax

This test has the following syntax:

/*<value>*/ starts with /*<prefix>*/
Try in Playground

To negate the test, you can write:

/*<value>*/ does not start with /*<prefix>*/
Try in Playground

Parameters

These are the supported parameters:

value

The string to validate.

prefix

The prefix that the string may start with.

Examples

Here is a basic example that checks if a string starts with another string:

"Hello world" starts with "Hello" // true
Try in Playground

You can negate the test to verify the contrary:

"Hello world" does not start with "Hello" // false
Try in Playground