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

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

Parameters

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

Returns

True if the string ends 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 = "test";
    var notfound = "xyz";
}#

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


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

Output

The #JS code above produces the output shown below:

<b>Ends with 'test', result:</b>
True

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