remove_last¶
Documentation for the 'remove_last' Filter in StringFilters
The remove_last filter is designed to remove the last occurrence of a specified substring from an input string.
Functionality
- Strings: Takes a string as input.
- Removal Target: Requires a string argument specifying the substring to remove.
- Last Occurrence: Only the final instance of the substring is removed from the input string.
- Output: Returns a new string with the last occurrence of the substring removed.
Syntax
Arguments
- string_to_remove: The substring that you want to remove from the end of the
input_string.
Code Samples
Example 1: Removing the Last Word
Output:
Example 2: Removing the Last Character Output: Example 3: Substring Not Found Output:Outliers and Special Cases¶
- Empty Strings: If the input string is empty, the
remove_lastfilter returns an empty string. - Substring Not Found: If the specified substring is not found in the input string, the original input string is returned unchanged.
- Empty Substring: If you try to remove an empty string, no change occurs.
- Non-String Input: If the input is not a string, the
remove_lastfilter might attempt to convert it to a string or return an error, depending on how Experience Builder handles type conversions.
Key Points¶
- The
remove_lastfilter is a precise tool for removing the final instance of a substring from a string. - It is case-sensitive, meaning "Word" and "word" are treated as different substrings.
- Consider using the
removefilter if you need to remove all occurrences of a substring. - You can combine this filter with other string manipulation filters to achieve more complex transformations.