strip¶
The strip filter is designed to remove leading and trailing whitespace characters from a string. It combines the functionality of both lstrip (removing leading whitespace) and rstrip (removing trailing whitespace).
Functionality
- Strings: Takes a string as input.
- Stripping: Removes any whitespace characters (spaces, tabs, newlines) from both the beginning and the end of the string.
- Output: Returns a new string with the leading and trailing whitespace removed.
Syntax
ArgumentsThe strip filter does not require any arguments.
Code Samples
Example 1: Removing Leading and Trailing Spaces
Output:
Example 2: Removing Whitespace Around a Code Block Output:Outliers and Special Cases¶
- Empty Strings: If the input string is empty, the
stripfilter returns an empty string. - Strings Without Whitespace: If the input string does not have any leading or trailing whitespace, the filter returns the original string unchanged.
- Non-String Input: If the input is not a string, the
stripfilter might attempt to convert it to a string or return an error, depending on how Experience Builder handles type conversions.
Key Points¶
- The
stripfilter is a convenient shortcut for removing whitespace from both ends of a string in a single operation. - It is particularly useful when normalizing text data, such as user input or data imported from external sources.
- Consider using
lstriporrstripif you need to remove whitespace from only one end of the string.