How to delete all leading and trailing spaces or specific characters from a string in the Anqi CMS template?
trim
/trimLeft
/trimRight
The filter can delete leading and trailing spaces or specific characters from a string separately.
trim
The filter can remove leading and trailing spaces or specific characters from a string;trimLeft
The filter can remove leading spaces or specific characters from a string;trimRight
The filter can remove trailing spaces or specific characters from a string.
Usage Instructions
trim
The usage of the filter
# 仅删除空格、换行符
{{obj|trim}}
# 或者 删除指定字符
{{obj|trim:关键词}}
For example, to delete a string欢迎使用安企CMS
Trailing spaces, you can write it like this:
{{" 欢迎使用安企CMS "|trim}}
# 显示结果
欢迎使用安企CMS
Delete a string欢迎使用安企CMS
Trailing characters欢迎CMS
then it can be written like this:
{{"欢迎使用安企CMS"|trim:"欢迎CMS"}}
# 显示结果
使用安企
trim
The filter also supports using it in assignment tags (set), storing the processing result in a variable, such as:
{% set source = "欢迎使用安企CMS(AnQiCMS)" %}
{% set result = source|trim:"欢迎" %}
{{result}}
# 显示结果
使用安企CMS(AnQiCMS)
trimLeft
The usage of the filter
# 仅删除空格、换行符
{{obj|trimLeft}}
# 或者 删除指定字符
{{obj|trimLeft:关键词}}
For example, to delete a string欢迎使用安企CMS
Leading spaces, it can be written like this:
{{" 欢迎使用安企CMS "|trimLeft}}
# 显示结果
欢迎使用安企CMS
Delete a string欢迎使用安企CMS
Leading characters欢迎
then it can be written like this:
{{"欢迎使用安企CMS"|trimLeft:"欢迎"}}
# 显示结果
使用安企CMS
trimLeft
The filter also supports using it in assignment tags (set), storing the processing result in a variable, such as:
{% set source = "欢迎使用安企CMS(AnQiCMS)" %}
{% set result = source|trimLeft:"欢迎" %}
{{result}}
# 显示结果
使用安企CMS(AnQiCMS)
trimRight
The usage of the filter
# 仅删除空格、换行符
{{obj|trimRight}}
# 或者 删除指定字符
{{obj|trimRight:关键词}}
For example, to delete a string欢迎使用安企CMS
Leading spaces, it can be written like this:
{{" 欢迎使用安企CMS "|trimRight}}
# 显示结果
欢迎使用安企CMS
Delete a string欢迎使用安企CMS
Leading characters欢迎
then it can be written like this:
{{"欢迎使用安企CMS"|trimRight:"CMS"}}
# 显示结果
欢迎使用安企
trimLeft
The filter also supports using it in assignment tags (set), storing the processing result in a variable, such as:
{% set source = "欢迎使用安企CMS(AnQiCMS)" %}
{% set result = source|trimRight:")" %}
{{result}}
# 显示结果
欢迎使用安企CMS(AnQiCMS
Here is an example demonstration
{{" 欢迎使用安企CMS(AnQiCMS) "|trim}}
# 显示结果
欢迎使用安企CMS(AnQiCMS)
{{"欢迎使用安企CMS(AnQiCMS)"|trim:"欢迎"}}
# 显示结果
使用安企CMS(AnQiCMS)
{{" 欢迎使用安企CMS(AnQiCMS) "|trimLeft}}
# 显示结果
欢迎使用安企CMS(AnQiCMS)
{{"欢迎使用安企CMS(AnQiCMS)"|trimLeft:"欢迎"}}
# 显示结果
使用安企CMS(AnQiCMS)
{{"欢迎使用安企CMS(AnQiCMS) "|trimRight}}
# 显示结果
欢迎使用安企CMS(AnQiCMS)
{{"欢迎使用安企CMS(AnQiCMS) "|trimRight:") "}}
# 显示结果
欢迎使用安企CMS(AnQiCMS