In my case all the strings are single-worded and the trailing whitespaces from the strings need to be removed, e.g., 'hello '
→ 'hello'
; 'hello '
→ 'hello'
.
One approach could be using split, i.e,
{% if ' ' in word %}
{% set word = word.split(' ')[0] %}
{% endif %}
This works since the strings are one-worded. I am quite sure there must be a better approach.
Use the . rstrip() method to remove whitespace and characters only from the end of a string.
We can eliminate the leading and trailing spaces of a string in Java with the help of trim(). trim() method is defined under the String class of java. lang package.
strip()—Remove Leading and Trailing Spaces. The str. strip() method removes the leading and trailing whitespace from a string.
Trailing whitespace. Description: Used when there is whitespace between the end of a line and the newline.
Silly me! It is .strip()
, i.e., 'hello '.strip()
.
It's not .strip()
... it's | trim
. Such as {{ some_variable_string_name | trim }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With