Delete all leading and trailing spaces, specific characters in a string

How to remove leading and trailing spaces or specific characters from a string in the Anqi CMS template?

trim/trimLeft/trimRightFilters can delete string beginning and end spaces and specific characters respectively.

  • trimFilters can remove string beginning and end spaces or specific characters;
  • trimLeftFilters can remove string leading spaces or specific characters;
  • trimRightFilters can remove string trailing spaces or specific characters.

How to use

trimHow to use filters

# 仅删除空格、换行符
{{obj|trim}}
# 或者 删除指定字符
{{obj|trim:关键词}}

For example, delete strings欢迎使用安企CMSThe beginning and end spaces of the slightest can be written like this:

{{" 欢迎使用安企CMS "|trim}}
# 显示结果
欢迎使用安企CMS

Delete string欢迎使用安企CMSThe beginning and end characters of欢迎CMS, you can write it like this:

{{"欢迎使用安企CMS"|trim:"欢迎CMS"}}
# 显示结果
使用安企

trimFilters also support the use in assignment labels (sets), storing the processing results into a variable, such as:

{% set source = "欢迎使用安企CMS(AnQiCMS)" %}
{% set result = source|trim:"欢迎" %}
{{result}}
# 显示结果
使用安企CMS(AnQiCMS)

trimLeftHow to use filters

# 仅删除空格、换行符
{{obj|trimLeft}}
# 或者 删除指定字符
{{obj|trimLeft:关键词}}

For example, delete strings欢迎使用安企CMSThe leading space of , can be written like this:

{{" 欢迎使用安企CMS "|trimLeft}}
# 显示结果
欢迎使用安企CMS

Delete string欢迎使用安企CMSLeading characters欢迎, you can write it like this:

{{"欢迎使用安企CMS"|trimLeft:"欢迎"}}
# 显示结果
使用安企CMS

trimLeftFilters also support the use in assignment labels (sets), storing the processing results into a variable, such as:

{% set source = "欢迎使用安企CMS(AnQiCMS)" %}
{% set result = source|trimLeft:"欢迎" %}
{{result}}
# 显示结果
使用安企CMS(AnQiCMS)

trimRightHow to use filters

# 仅删除空格、换行符
{{obj|trimRight}}
# 或者 删除指定字符
{{obj|trimRight:关键词}}

For example, delete strings欢迎使用安企CMSThe leading space of , can be written like this:

{{" 欢迎使用安企CMS "|trimRight}}
# 显示结果
欢迎使用安企CMS

Delete string欢迎使用安企CMSLeading characters欢迎, you can write it like this:

{{"欢迎使用安企CMS"|trimRight:"CMS"}}
# 显示结果
欢迎使用安企

trimLeftFilters also support the use in assignment labels (sets), storing the processing results into a variable, such as:

{% set source = "欢迎使用安企CMS(AnQiCMS)" %}
{% set result = source|trimRight:")" %}
{{result}}
# 显示结果
欢迎使用安企CMS(AnQiCMS

Sample Demo

{{" 欢迎使用安企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