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

How to delete all spaces or specific characters in the beginning and end of a string in 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

# Remove only spaces, line breaks
{{obj|trim}}
# or delete the specified character
{{obj|trim:keyword}}

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

{{" Welcome to Anqi CMS "|trim}}
# Show results
 Welcome to Anqi CMS

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

{{"Welcome to use Anqi CMS"|trim:"Welcome to use CMS"}}
# Show results
Use Anqi

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

{% set source = "Welcome to AnQiCMS (AnQiCMS)" %}
{% set result = source|trim:"Welcome" %}
{{result}}
# Show results
Use AnQiCMS (AnQiCMS)

trimLeftHow to use filters

# Remove only spaces and line breaks
{{obj|trimLeft}}
# or delete the specified character
{{obj|trimLeft:Keyword}}

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

{{" Welcome to Anqi CMS "|trimLeft}}
# Show results
Welcome to Anqi CMS

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

{{"Welcome to use Anqi CMS"|trimLeft:"Welcome"}}
# Show results
Use Anqi CMS

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

{% set source = "Welcome to AnQiCMS (AnQiCMS)" %}
{% set result = source|trimLeft:"Welcome" %}
{{result}}
# Show results
Use AnQiCMS (AnQiCMS)

trimRightHow to use filters

# Remove only spaces and line breaks
{{obj|trimRight}}
# or delete the specified character
{{obj|trimRight:Keyword}}

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

{{" Welcome to Anqi CMS "|trimRight}}
# Show results
Welcome to Anqi CMS

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

{{"Welcome to use Anqi CMS"|trimRight:"CMS"}}
# Show results
Welcome to use Anqi

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

{% set source = "Welcome to AnQiCMS (AnQiCMS)" %}
{% set result = source|trimRight:")" %}
{{result}}
# Show results
Welcome to AnQiCMS (AnQiCMS)

Sample Demo

{{" Welcome to AnQiCMS (AnQiCMS) "|trim}}
# Show results
 Welcome to AnQiCMS (AnQiCMS)
{{"Welcome to use AnQiCMS (AnQiCMS)"|trim:"Welcome"}}
# Show results
Use AnQiCMS (AnQiCMS)
{{" Welcome to AnQiCMS (AnQiCMS) "|trimLeft}}
# Show results
 Welcome to AnQiCMS (AnQiCMS)
{{"Welcome to use AnQiCMS (AnQiCMS)"|trimLeft:"Welcome"}}
# Show results
Use AnQiCMS (AnQiCMS)
{{"Welcome to use AnQiCMS (AnQiCMS)"|trimRight}}
# Show results
Welcome to use AnQiCMS (AnQiCMS)
{{"Welcome to use AnQiCMS (AnQiCMS) "|trimRight:") "}}
# Show results
Welcome to use AnQiCMS (AnQiCMS)