How to delete all spaces or specific characters in the beginning and end of a string in Anqi CMS template?
trim
,trimLeft
,trimRight
Filters can delete string beginning and end spaces and specific characters respectively.
trim
Filters can remove string beginning and end spaces or specific characters;trimLeft
Filters can remove string leading spaces or specific characters;trimRight
Filters can remove string trailing spaces or specific characters.
How to use
trim
How to use filters
# Remove only spaces, line breaks {{obj|trim}} # or delete the specified character {{obj|trim:keyword}}
For example, delete strings欢迎使用安企CMS
The 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欢迎使用安企CMS
The 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
trim
Filters 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)
trimLeft
How to use filters
# Remove only spaces and line breaks {{obj|trimLeft}} # or delete the specified character {{obj|trimLeft:Keyword}}
For example, delete strings欢迎使用安企CMS
The leading space of , can be written like this:
{{" Welcome to Anqi CMS "|trimLeft}} # Show results Welcome to Anqi CMS
Delete string欢迎使用安企CMS
Leading characters欢迎
, you can write it like this:
{{"Welcome to use Anqi CMS"|trimLeft:"Welcome"}} # Show results Use Anqi CMS
trimLeft
Filters 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)
trimRight
How to use filters
# Remove only spaces and line breaks {{obj|trimRight}} # or delete the specified character {{obj|trimRight:Keyword}}
For example, delete strings欢迎使用安企CMS
The leading space of , can be written like this:
{{" Welcome to Anqi CMS "|trimRight}} # Show results Welcome to Anqi CMS
Delete string欢迎使用安企CMS
Leading characters欢迎
, you can write it like this:
{{"Welcome to use Anqi CMS"|trimRight:"CMS"}} # Show results Welcome to use Anqi
trimLeft
Filters 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)