PowerApps Trim Function

In this Power Apps tutorial, we will discuss what is Trim and TrimEnds functions in PowerApps, its all syntaxes, and how we can use both the functions in PowerApps.

Also, we will cover all the below topics:

  • What is PowerApps Trim Function
  • PowerApps Trim Function Syntax
  • What is PowerApps TrimEnds Function
  • PowerApps TrimEnds Function Syntax
  • PowerApps Trim and TrimEnd Function Examples
  • PowerApps trim last character
  • How to work with PowerApps trim all spaces
  • Work with PowerApps trim time from date
  • What is PowerApps trim left
    • PowerApps Left Function
    • PowerApps Left Function Syntax
  • PowerApps trim first character
  • How to remove special characters from string in PowerApps
  • PowerApps remove character from string
  • How to remove last character from string in PowerApps

PowerApps Trim Function

PowerApps Trim function is a type of function that helps to remove all the spaces from a text string except for single spaces between words.

PowerApps Trim Function Syntax

The below code represents the syntaxes of the PowerApps Trim function.

Syntax – 1:

Trim( String )

Where,

String = This is required. The string of text to remove spaces from.

Syntax – 2:

Trim( SingleColumnTable )

Where,

SingleColumnTable = This is also required. A single-column table of strings to remove spaces from.

PowerApps TrimEnds Function

PowerApps TrimEnds Function is a type of function that removes all the spaces from the start and end of a string of text but leaves spaces between words intact.

PowerApps TrimEnds Function Syntax

The below code represents the syntaxes of the PowerApps TrimEnds function.

Syntax – 1:

TrimEnds( String )

Where,

String = This is required. The string of text to remove spaces from.

Syntax – 2:

TrimEnds( SingleColumnTable )

Where,

SingleColumnTable = This is also required. A single-column table of strings to remove spaces from.

Read: PowerApps Search User

PowerApps Trim and TrimEnd Function Examples

The below table represents a sample formula of PowerApps Trim and TrimEnd functions, their descriptions, and their outputs.

Formula Description Output
Trim( ” Welcome to PowerApps ” ) It helps to remove all spaces from the start and end of a string and extra spaces from within the string. “Welcome to PowerApps”
TrimEnds( ” Welcome to PowerApps ” ) It helps to remove all spaces from the start and end of a string. “Welcome to PowerApps”

Example:

  • In this example, We will use a single-column collection named colSentences. To create the string collection, I have taken a Button control (Click Me) and applied the below code on its OnSelect property as:
OnSelect = ClearCollect(
    colSentences,
    [
        "   Let   him   play   ",
        "    This   book   is   torn",
        "No way any more",
        "   Left,   Right,   Middle  ",
        "Make it hurry   "
    ]
)

Where,

colSentences = Collection name

To read the details of PowerApps Collection, you can refer to this link: Create Collection from SharePoint List in PowerApps

PowerApps Trim function
  • Next, insert a Gallery control and set its Items property to the below code:
Items = Trim(colSentences)

Where,

Trim(colSentences) = This helps to trim all the spaces from the start and end of each string and extra spaces from within each string in the colSentences collection.

Power Apps Trim function
Power Apps Trim function
  • Now save and preview the app. When you will tap on the button (Click Me), you can see the trim result in the gallery control as shown below.
PowerApps Trim

NOTE:

If you will open the collections, then you can see the extra spaces don’t appear by clicking on the collections name. For this type of string length, you can use the PowerApps Len function.
  • Similarly if you want to use the TrimEnds function, then overlook the below code and its result in the gallery control. Set this function on gallery’s Items property as:
Items = TrimEnds(colSentences)

Where,

TrimEnds(colSentences) = Trims all spaces from the start and end of each string in the colSentences collection.

PowerApps TrimEnds function
PowerApps TrimEnds function

So this is a simple example of PowerApps Trim and TrimEnds functions.

PowerApps trim last character

Here we will see how to trim or remove the last character from a string in PowerApps.

  • Let’s say I have a string as “Jack,Shed,John,Rome,Gold,” in a label control. Now I would like to remove the addtional “,” at the end of the string.
  • In the below screenshot, you can see the label contains the strings on its Text property.
PowerApps trim last character
PowerApps trim last character
  • Now, to trim the last character “,” from the string, you can set the below code on label’s Text property as:
Text = Left(
    "Jack,Shed,John,Rome,Gold,",
    Len("Jack,Shed,John,Rome,Gold,") - 1
)

Where,

Len = It is a PowerApps function that helps to return the length of a string of a text.

  • Once you will apply the formula, you can see the last character will remove from the string as like the below screenshot.
Power Apps trim last character

This is how to work with PowerApps trim last character.

PowerApps trim all spaces

Do you want to remove all the spaces from a text string? Check out the below scenario.

  • In the below screenshot, there is a Text input control and as well as a Label control. When a user will enter the text in the text input box (including spaces), then it will remove all the spaces from the text field and the result will display in the label control.
PowerApps trim all spaces
PowerApps trim all spaces
  • To achieve this, we will use the PowerApps Substitute function. Select the label control and apply the below code on its Text property as:
Text = Substitute(TextInput1.Text," ","")

Where,

  1. Substitute = PowerApps Substitute function helps to identify the text to replace by matching a string.
  2. TextInput1 = Text input control name where the user will enter the text string.
Power Apps trim all spaces

This is how to work with PowerApps trim all spaces.

PowerApps trim time from date

Do you want to trim or remove the time from the PowerApps date? Check out the below scenario.

  • There is a Gallery control where the records are retrieved from a SharePoint List named Products. In this list, there is a SharePoint Date Time field called Sales Date.
  • Now I would like to trim the time from the SharePoint Sales Date. That means, it will only display the date in the gallery.
PowerApps trim time from date
PowerApps trim time from date
  • By default, when you will add the date field in the gallery, then the label’s Text property will be like below:
Text = ThisItem.'Sales Date'
  • The above code retrieves the Product Sales Date including time from the SharePoint List. Now to remove the time from the date, you can use the below code:
Text = Text(
    ThisItem.'Sales Date',
    "dd-mmm-yy"
)

Where,

dd-mmm-yy” = You can specify the date format that you want to view in the gallery.

PowerApps remove time from date
PowerApps remove time from date
  • Once you will put the above code, you can view the gallery date field will display with only Date format as “20-Nov-21“.
  • Also, you can use the below functions and date formats in gallery control.
  1. The below code will give the output as 05:20:10 PM
Text(ThisItem.'Sales Date',DateTimeFormat.LongTime)

2. The below code will give the output as 05:20 PM

Text(ThisItem.'Sales Date',DateTimeFormat.ShortTime)

3. The below code will give the output as 01/14/2021

Text(ThisItem.'Sales Date',DateTimeFormat.ShortDate)

This is how to work with PowerApps trim time from date.

PowerApps trim left

So, there is no specific function in PowerApps that can help to trim the left position of the string. Instead of that, we can use the PowerApps Left function.

PowerApps Left Function

PowerApps Left Function is a type of function that helps to return the beginning characters of a string.

PowerApps Left Function Syntax

The below represents the syntaxes of PowerApps Left function.

Syntax – 1:

Left( String, NumberOfCharacters )

Where,

  1. String = This is required. The string to from which to extract the result.
  2. NumberOfCharacters = This is also required. It specifies the number of characters to return.

Syntax – 2:

Left( SingleColumnTable, NumberOfCharacters )

Where,

  1. SingleColumnTable = This is a required parameter. A single-column table of strings from which to extract the results.
  2. NumberOfCharacters = This is also required. It specifies the number of characters to return.

To learn more details about the PowerApps Left function, refer to this MSDN: PowerApps Left Function

PowerApps trim first character

Here we will see how to work with PowerApps trim first character.

  • In the app, there is a Text input control (with multi-line) and a Label control. User will enter their addresses in the text box and then it will trim some character from the string (like first character, middle character, last character, etc.), and the result will display in the label control.
  1. In the below screenshot, it will extract only the first character from the text string (address). As the first character is John, so the result is appearing in the label control. For this, we will use the Split function and as well as the PowerApps FirstN and Last function.
PowerApps trim first character
PowerApps trim first character
  • Select the Label control and apply the below code on its Text property as:
Text = First(
    Split(
        txtAddress.Text,
        " "
    )
).Result

Where,

txtAddress = Text input control name

Power Apps trim first character
how to trim first character in PowerApps

2. Suppose in the label control, you want to get the second line of the string i.e. Manager Marketing. Then you need to follow the below formula.

PowerApps remove first character
Power Apps remove first character
  • Select the Label control and apply the below code on its Text property as:
Text = Trim(
    Last(
        FirstN(
            Split(
                txtAddress.Text,
                ","
            ),
            2
        )
    ).Result
)

Where

  • Last = This function helps to return the last item or record of a data source or a table.
  • FirstN = This PowerApps function helps to return the first set of records of a table whereas the second argument defines the number of records that to be returned.
Power Apps remove first character

3. In this scenario, it will extract the second last block of text in the address when separated by the comma character i.e. ST, as in the below screenshot.

Remove first character in PowerApps
Power Apps remove first character
  • Select the Label control and apply the below code on its Text property as:
Text = Trim(
    First(
        LastN(
            Split(
                txtAddress.Text,
                " "
            ),
            2
        )
    ).Result
)

Refer to the below screenshot.

Remove first character in Power Apps
Remove first character in Power Apps

4. Now to get the last character of the text string, you can follow the below formula. As the last character contains the Pincode, so it is displaying in the label as shown below.

how to remove first character in PowerApps
  • Select the Label control and apply the below code on its Text property as:
Last(
    Split(
        txtAddress.Text,
        " "
    )
).Result
how to trim first character in PowerApps
how to trim first character in PowerApps

This is how to work with PowerApps trim first character.

PowerApps remove special characters from string

Do you want to remove the special characters from string or do you want to validate a field for the special character in PowerApps? Please check out this link to get the details: Remove special characters from string in PowerApps

PowerApps remove character from string

Here we will see how to remove a character from a string in PowerApps. Let us take a simple scenario.

  • In the below scenario, I have a Text input control and as well as a Label control. In the text box, a user will enter the mobile number with a special character ““. Now I would like to block every “” character that it is entered in it as shown in the below screenshot.
PowerApps remove character from string
PowerApps remove character from string
  • To achieve this, we will use the PowerApps Substitute function. Select the Label control and apply the below code on its Text property as:
Text = Substitute(
    txtPhnNumber,
    "-",
    ""
)

You can substitute any character like “/”, “;”, “*”, etc as per your need.

Power Apps remove character from string
Power Apps remove character from string

This is how to work with PowerApps remove character from string.

PowerApps remove last character from string

To work with the PowerApps remove last character from string, check out this PowerApps forum link: Remove the last character in powerApps string

Also, you may like the below PowerApps Tutorials:

In this PowerApps tutorial, we discussed what is Trim and TrimEnds functions in PowerApps, its all syntaxes, and how to use both the functions in PowerApps.

Also, we will cover all the below topics:

  • PowerApps Trim Function
  • PowerApps Trim Function Syntax
  • PowerApps TrimEnds Function
  • PowerApps TrimEnds Function Syntax
  • PowerApps Trim and TrimEnd Function Examples
  • PowerApps trim last character
  • PowerApps trim all spaces
  • PowerApps trim time from date
  • PowerApps trim left
    • PowerApps Left Function
    • PowerApps Left Function Syntax
  • PowerApps trim first character
  • PowerApps remove special characters from string
  • PowerApps remove character from string
  • PowerApps remove last character from string
>