Power Apps Trim | Power Apps Remove First Character from String

I recently received a task in which I needed to remove the first and last characters from a string and all spaces from the string in Power Apps. Fortunately, Microsoft Power Apps provides Trim and TrimEnds Functions to achieve this.

In this Power Apps tutorial, I will explore all the information about the Power Apps Trim function, Power Apps TrimEnds function, and Power Apps remove first character from string.

Also, we will see how to work with Power Apps remove last character from string, Power Apps replace spaces in string, and Power Apps remove special characters from string with examples.

Trim Function in Power Apps

The Power Apps Trim function removes all spaces from a text string except for single spaces between words.

Power Apps Trim Function Syntaxes:

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

trim in powerapps

TrimEnds Function in Power Apss

Power Apps TrimEnds Function removes all spaces from the start and end of a string of text but leaves spaces between words intact.

Power Apps TrimEnds Function Syntaxes:

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

trimend in powerapps

Power Apps Remove First Character from String

Suppose you want to remove the first character from the string. You can follow the code below.

Text = Right(
    " A Power Apps Tutorial",
    Len("A Power Apps Tutorial") - 1
)

Where,

  • ” A Power Apps Tutorial” = Power Apps string value
power apps remove first character from string

In this example, I have a Text label control that contains the string ” A Power Apps Trim Function.” Now, I would like to remove the first character[“A”] from the string. To do so, follow the code below.

Text = Mid(
    "A Power Apps Trim Function",
    2,
    Len("A Power Apps Trim Function") - 1
)
powerapps remove first character from string

This is how we can remove the first character from a string in Power Apps.

Power Apps Get First Character from String

To get the first character from the Power Apps string, follow the code below.

Text = Trim(
    Last(
        FirstN(
            Split(
                txt_Address.Text,
                ","
            ),
            1
        )
    ).Value
)

Where,

  • txt_Address = Power Apps text input control name
Power Apps Get First Character from String

Power Apps Remove Last Character from String

Let’s say I have a string as “IT,Sales,HR,Finance,Marketing,” in a Text label control. Now, I would like to remove the additional last character “,” at the end of the string.

To achieve it, follow the code below.

Text = Left(
    "IT,Sales,HR,Finance,Marketing,",
    Len("IT,Sales,HR,Finance,Marketing,") - 1
)
powerapps remove last character from string

Power Apps Get Last Character from String

In this example, I will show you how to get the last character from a string in Power Apps. To do so, follow the code below.

Text = Last(
    Split(
        txt_Address.Text,
        " "
    )
).Value
Power Apps Get Last Character from String

Power Apps Remove Spaces from String

Next, I will show you how to remove spaces from a string in Power Apps. Follow the code below.

Text = Substitute(
    txt_Address.Text,
    " ",
    ""
)
powerapps remove spaces from string

Similarly, in Power Apps, there is a single-column collection named colSentences. To create the string collection, I took a Button control (Click Me) and applied the code below to its OnSelect property.

OnSelect =  ClearCollect(
    colSentences,
    [
        "   Let   him   play   ",
        "    This   book   is   torn",
        "No way any more",
        "   Left,   Right,   Middle  ",
        "Make it hurry   "
    ]
)

Where,

  • colSentences = Collection name
powerapps remove all spaces from string

Next, insert a Gallery control and set its Items property to the below code:

Items = Trim(colSentences)
power apps remove all spaces from string

Now save and preview the app. When you tap on the button (Click Me), the trim result [Without spaces] will appear in the gallery control, as shown below.

remove all spaces from string in powerapps

Note:

If you 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 Power Apps Len function.

Power Apps Replace Spaces in String

Finally, I will show you how to replace spaces in the Power Apps string with a simple example.

Example:

In Power Apps, I have a variable having the text value “Welcome To PowerApps” that contains some spaces. Now, I want to replace those spaces with a different character, such as an underscore “_.”

To work around this, follow the below steps. Such as:

1. On the Power Apps app, select the App object [From the left navigation] and set its OnStart property, as shown below.

OnStart = Set(varText, "Welcome To PowerApps")

Where,

  • varText = Power Apps variable name
powerapps replace spaces in string

2. Next, on the Power Apps, insert a Text label and set its Text property to the code below.

Text = Substitute(
    varText,
    " ",
    "_"
)

This way, you can work with the Power Apps replace spaces in string.

power apps replace spaces in string

Power Apps Remove Special Characters from String

Do you want to remove the special characters from the 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

I trust this Power Apps tutorial is helpful for you. In this article, we learned what is trim in PowerApps, PowerApps remove first character from string, and PowerApps remove last character from string with examples.

Some more articles you may also like:

>