endsWith

The endsWith task searches a given string to determine whether a specified sequence of characters appears at the end. You can also limit the number of characters searched. The task returns true if the string ends with the characters, or false if they are not found. The original string is not changed.

To check whether a string begins with a specified sequence instead, use the startsWith task.

Potential use case

Use endsWith to check whether a filename ends with a certain extension. For example, to check whether filename.txt ends with .txt, run endsWith against your file list. A true result confirms the extension is present; a false result confirms it is not. You can also use the length parameter to limit the search to only the beginning portion of the list.

Properties

IncomingTypeDescription
strStringRequired. The string to search.
searchStringStringRequired. The characters to search for at the end of the string.
lengthNumberThe length of the string to search. If omitted, the full string is searched.
OutgoingTypeDescription
resultBooleantrue if searchString is found at the end; false otherwise.

Example 1

In this example:

  • str is "Hello world, welcome to the universe."
  • searchString is "universe."
  • length is not specified, so the entire string is searched.
  • The expected result is true.
endsWith task with searchString 'universe.' and no length limit

Example 2

In this example:

  • str is the same as example one.
  • searchString is "world".
  • length is specified — only the first 11 characters of the string are searched.
  • The expected result is true, because "world" is found at the end of the first 11 characters.
endsWith task with searchString 'world' and length set to 11