Remove all leading and trailing spaces, and specific characters from a string

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

trim/trimLeft/trimRightThe filter can delete leading and trailing spaces or specific characters from a string separately.

  • trimThe filter can remove leading and trailing spaces or specific characters from a string;
  • trimLeftThe filter can remove leading spaces or specific characters from a string;
  • trimRightThe filter can remove trailing spaces or specific characters from a string.

Usage Instructions

trimThe usage of the filter

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

For example, to delete a string欢迎使用安企CMSTrailing spaces, you can write it like this:

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

Delete a string欢迎使用安企CMSTrailing characters欢迎CMSthen it can be written like this:

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

trimThe 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)

trimLeftThe usage of the filter

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

For example, to delete a string欢迎使用安企CMSLeading spaces, it can be written like this:

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

Delete a string欢迎使用安企CMSLeading characters欢迎then it can be written like this:

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

trimLeftThe 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)

trimRightThe usage of the filter

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

For example, to delete a string欢迎使用安企CMSLeading spaces, it can be written like this:

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

Delete a string欢迎使用安企CMSLeading characters欢迎then it can be written like this:

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

trimLeftThe 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