String.startsWith(text) Last updated: 13. Nov 2023

Searches the start of the string, and returns a boolean that is True if the string starts with this text otherwise False.

Parameters

Name Type Description
text string Sub string to check if string starts with. Case sensitive.

Returns

True if the string starts with the specified text otherwise False.

Example

Code example (#JS)

#JS is mixed HTML (or other text file) with inline JavaScript with # starting and ending each inline statement.
#{
    var text = "This is a test";
    var search = "This";
    var notfound = "xyz";
}#

<b>Starts with '#search#', result:</b>
#{
    var result = text.startsWith(search);
    write(result);
}#


<b>Not starts with '#notfound#', result:</b>
#{
    result = text.startsWith(notfound);
    write(result);    
}#

Output

The #JS code above produces the output shown below:

<b>Starts with 'This', result:</b>
True

<b>Not starts with 'xyz', result:</b>
False