Skip to content
Home » TrimEnds function in Power Apps

TrimEnds function in Power Apps

The TrimEnds function in Power Apps is used to remove any leading and trailing spaces from a string.

It helps clean up text input by eliminating unnecessary spaces at the beginning and end of the string, but leaves spaces between words intact.




If you specify a single-column table that contains strings, the return value is a single-column table of trimmed strings

Syntax:

TrimEnds(String)

String: Required, The text string from which leading and trailing spaces will be removed.

or

TrimEnds(SingleColumnTable)

String: Required. A single-column table of strings to remove spaces from.

Using TrimEnds function

Example 1:

TrimEnds(" Remove leading and trailing spaces  ")

This formula will return “Remove leading and trailing spaces”. The spaces before and after the text are removed.

Example 2:

TrimEnds("Remove trailing spaces      ")

In this case, the TrimEnds function removes the trailing spaces after the text “Remove trailing spaces  “ but does not affect any spaces within the string itself.

It will return “Remove trailing spaces”.

Example 3:

Assume you have a single column collection named colData_source  and you want to remove leading and trailing spaces from the Val field and store the updated data in another collection colData_target.
Here’s the source collection colData_source  which includes the column Val.
ClearCollect(
  colData_source,
  {Val: "Hello   "},
  {Val: "   There  "},
  {Val: " Learn Power Apps  "}
)
Let’s add a button control, go to OnSelect property of button and write the above formula.

Now, run the app and click the button. A collection named colData_source will be created, containing 3 records.

Let’s use the TrimEnds function to remove spaces from the Val column while copying the updated records into another collection colData_target.




Now, add another button. Go to OnSelect property of button and write the below formula.

ClearCollect(
    colData_target,
    ForAll(
        colData_source,
        {Val: TrimEnds(Val)}
    )
)

Let’s run the App, and you can see it creates a new collection colData_target having the Val field cleaned of leading and trailing spaces.

 

Read Also..

Loading

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.