How to Remove Last/LastN Character From String in Power Apps?

Recently, while working with Power Apps, I had a common task to remove the last character from a string.

This can be a useful scenario, so I decided to share a post about it.

In this Power Apps tutorial, I will explain how to remove Last/LastN Character from string in Power Apps with various examples.

How to Remove Last/LastN Character From String in Power Apps

Let’s remove the last character from a string in Power Apps with different scenarios. Such as:

  1. Remove the last character from a string in Power Apps [Manually]
  2. Remove the last n characters from a string in Power Apps
  3. Power Apps remove the last character from the SharePoint text column

Example 1: [Remove the last character from a string in Power Apps Manually]

Let us see how to remove the last character from a string in Power Apps.

Example:

In Power Apps, there is a Text input control [Provide URL] and a Label control [Result].

When a user provides a text/string in a text input box, it will remove the last character (/) from the specific string and display the result in the label, as shown below.

Power Apps remove last character from string

To achieve it, follow the below steps:

  • On the Power Apps screen, insert a Text input control, as shown below:
How to remove last character from string in Power Apps
  • Insert a Text label control and set its Text property to:
Left(
    txt_URL.Text,
    Len(txt_URL.Text) - 1
)

Where,

  1. txt_URL = Text-input control name
Remove last character from string in Power Apps
  • SavePublish, and Preview the app. When you provide the string in the text box, it will remove the last character from that string, i.e., “/,” as shown below:
Remove last character from string Power Apps

This is how to remove the last character from a string in Power Apps.

Example 2: [Remove the last n characters from a string in Power Apps]

Here, let us see how to remove the last n characters from a string in Power Apps.

Example:

There is a Text input control and a Label control. When a user provides an Employee ID including a year, e.g., “2015, ” the last four digits of the given number will be removed, and the result will appear in the label control.

How to remove N characters from string in Power Apps

Follow the below steps to achieve it:

  • On the Power Apps screen, insert a Text input control as shown below:
Remove n characters from the last of a string in Power Apps
  • Add a Text label control and set its Text property as:
With({
        input: txt_EmployeeID.Text,
        ltrim: Year(txt_EmployeeID.Text)
     },
     If(StartsWith( input, ltrim),        
        Left(input, Len(input) - Len(ltrim)),
        input
     )   
)

Where,

  1. txt_EmployeeID = Text-input control name
  2. ltrim = It removes all spaces or a provided text
Remove n characters from the last of a string Power Apps
  • SavePublish, and Preview the app. When the employee enters an ID ending with a year in the text box, it will delete the last 4 digits year as shown below.
How to remove n characters from the last of a string in Power Apps

We can achieve this by removing the last n characters from the string in Power Apps.

Example 3: [Power Apps remove the last character from the SharePoint Text column]

Lets us check how to remove the last character from a SharePoint text field.

Example:

I have a SharePoint list [Project Details] that has a title column as “Project Name,” as shown below:

How to remove n characters from the last of a string in Power Apps using SharePoint list

On my Power Apps screen, I have added an Edit form connected to the above SharePoint list. Since the ‘Project Name’ is a text field, it displays as a Text-input control in the form.

When a user provides a project name that ends with a comma [,] in the “Project Name” field and submits the form, the text will remove a comma in the SharePoint list, as shown below:

Power Apps remove last character from string using SharePoint list

Follow the below steps to achieve this:

  • On the Power Apps screen, insert an Edit form -> Set its DataSource property to:
'Project Details'

Where,

  1. Project Details = Above SharePoint list name
Remove last character from string in Power Apps using SharePoint list
  • Insert a Button control and apply the code below on its OnSelect property:
Patch(
    'Project Details',
    Defaults('Project Details'),
    {
        Title: With(
            {
                input: DataCardValue3.Text,
                rtrim: ","
            },
            If(
                EndsWith(
                    input,
                    rtrim
                ),
                Left(
                    input,
                    Len(input) - Len(rtrim)
                ),
                input
            )
        ),
        'Project Handled By': DataCardValue8.Selected
    }
)

Where,

  1. Project Details = Above SharePoint list name
  2. Title = SharePoint list title column
  3. DataCardValue3 = Text-input control name
  4. Project Handled By = SharePoint list person column name
  5. DataCardValue8 = Combo box control name
Remove n characters from the last of a string in Power Apps using SharePoint list
  • SavePublish, and Preview the app. The user will enter the form details, including the project name that ends with a comma[,], and click the SUBMIT button.
How to remove n characters from last of a string in Power Apps using SharePoint list
  • Go to the specific SharePoint list and refresh it. You will view the new record that the project name will remove the last character of the string, as shown below:
Power Apps remove last character from string using SharePoint list

This is how to remove the last character from a string using a SharePoint list text field.

Additionally, you may like some more Power Apps articles:

Conclusion

I hope this Power Apps article helped you to remove Last/Last N characters from a string in various ways:

  1. Remove the last character from a string in Power Apps manually
  2. Power Apps remove the last character from a SharePoint text column