The Trim function in PowerApps is used to remove all spaces from a text string except for single spaces between words. This function is useful for cleaning up user input or data retrieved from external sources, ensuring that spaces do not affect data processing or comparisons.
PowerApps – Trim() function Syntax
- Text: The text string from which you want to remove leading and trailing spaces.
PowerApps – Remove leading and trailing spaces
To remove leading and trailing spaces and extra spaces in between the words from the text " Hello World ":
This returns "Hello World" without the leading and trailing spaces and without extra spaces in between the words.
PowerApps - Trim Data from a Text Input
If you have a text input control named TextInput1 and you want to trim the input text:
When validating user input, you can use the Trim function to ensure that spaces do not affect the validation logic:
If(IsBlank(Trim(TextInput1.Text)), Notify("Input cannot be empty", NotificationType.Error))
PowerApps – Compare trimmed text values
When comparing text values, trimming spaces can prevent mismatches due to extra spaces:
If(Trim(TextInput1.Text) = "Admin", Notify("Welcome, Admin!", NotificationType.Success))