Purpose
The endsWith task is used to search a given string to determine if a string (or specified sequence of characters) is included at the end. With this task method, you can also specify the number of characters in the string to be searched. A result of "True" indicates the string ends with the characters, and "False" if the characters are not found. Of note, this task does not change the value of the original string.
In contrast to endsWith, if you want to check if a string begins with the characters of a specified string, use the startsWith task.
Potential Use Case
You could potentially use this task if you want to check if a filename in a particular list endsWith a certain extension. For example, to check if filename.txt ends with .txt, you could use this task to perform a search on your list. A "True" result would tell you there is a filename that includes the extension; a "False" result would tell you that a filename with that extension was not found. Depending on the length of the list, you could also set the endsWith task to limit its search to only the beginning portion of your list.
Properties
| Incoming | Type | Description |
|---|---|---|
str |
String | Required. The string to search. |
searchString |
String | Required. The string (or sequence) of characters to search for at the end of a given string. |
length |
Number | The length of the string that will be searched. If omitted, the default is to search the full length of the string. |
| Outgoing | Type | Description |
|---|---|---|
result |
Boolean | Returns true if the searchString is found, false otherwise. |
Examples
Example 1
In this IAP example:
The input
strvariable is "Hello world, welcome to the universe."The
searchStringvalue to search for is "universe."In this example, the
lengthis not specified, so the entire string will be searched.The expected
resultwill be "True", indicating that"universe."was found at the end of the string.
Example 2
In this IAP example:
The same input
stris used, but thesearchStringvalue is "world".The
lengthparameter is specified. Only the first 11 characters of the string will be searched.The expected
resultwill return "True", indicating that"world"was found at end of the specified length.