How to Remove First/FirstN Character From String in Power Apps?

One common thing that people frequently search for is removing the first character from a string in Power Apps.

Let’s say a person enters their name with an additional space from the beginning. Then, removing the initial character/space from the string in Power Apps is possible.

In this Power Apps tutorial, I will show you how to remove first/firstN character from string in Power Apps with various approaches.

How to Remove First/FirstN Character From String in Power Apps

In this section, we will discuss removing the first character from a string in Power Apps with different scenarios:

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

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

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

Example:

In Power Apps, there is a Text input control [Provide your favorite place to visit] and a Label control [Result].

When a user enters text or a string in a text input box, the text input box will eliminate the initial character (=) from that particular string and display the result in the label shown below.

How to remove the first character from string in Power Apps

To achieve it, follow the below steps:

  • On the Power Apps screen, insert a Text input control, as shown below:
Remove the first character from string in Power Apps
  • Add a Text label control and set its Text property as:
Right(
    txt_Places.Text,
    Len(txt_Places.Text) - 1
)

Where,

  1. txt_Places = Text input control name
How to remove Power Apps first character from string
  • SavePublish, and Preview the app. The first character (=) from a given string is removed when a user enters a text in the text box, and the result is displayed in the label below.
Remove Power Apps first character from string

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

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

Here, let us see how to remove a set of characters from the first of a string in Power Apps.

Example:

There is a Text input control and a Label control. When a user provides a telephone number with a country code including a space, i.e., “+1 “, it will remove all the starting three characters from the given number.

Also, the result will be displayed in the label control, as shown below.

Remove n characters from the first of a string in Power Apps

To work around this, follow the below steps:

  • On the Power Apps screen, insert a Text input control as shown below:
Power Apps remove n characters from first of a string
  • Add a Text label and set its Text property as:
With({
        input: txt_EmpPhoneNumber.Text,
        ltrim: "+1"
     },
     If(StartsWith( input, ltrim),        
        Right(input, Len(input) - Len(ltrim)),
        input
     )   
)

Where,

  1. txt_EmpPhoneNumber = Text input control name
How to remove n characters from the first of a string in Power Apps
  • SavePublish, and Preview the app. When the employee enters a phone number starting with a country code [+1 ] in the text box, it will delete all the first three characters (+, 1, and space) as shown below:
Power Apps remove first n characters from string

This way, we can remove the first n characters from a string in Power Apps.

Example 3: [Power Apps remove the first character from a SharePoint text column]

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

Example:

I have a SharePoint list [Product Transaction Details] that has a title column as “Product ID,” as shown below:

Power Apps remove first character from string using SharePoint list

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

When a user provides a product ID that starts with a company code “ACGH” in the “Product ID” field and submits the form, the text will remove a company code ACGH in the SharePoint list, as shown below:

Power Apps remove first character from string using the SharePoint list

Follow the below steps to achieve this:

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

Where,

  1. Product Transaction Details = Above SharePoint list name
Remove first character from string using a SharePoint list in Power Apps
  • Insert a Button control and apply the code below on its OnSelect property:
Patch(
    'Product Transaction Details',
    Defaults('Product Transaction Details'),
    {
        Title: With(
            {
                input: DataCardValue9.Text,
                ltrim: "ACGH"
            },
            If(
                StartsWith(
                    input,
                    ltrim
                ),
                Right(
                    input,
                    Len(input) - Len(ltrim)
                ),
                input
            )
        ),
        'Supplied Product': DataCardValue10.Selected,
        'Is Paid Or Not': DataCardValue12.Value,
        'Product Supplied Date': DataCardValue13.SelectedDate
    }
)

Where,

  1. Product Transaction Details = Above SharePoint list name
  2. Title = SharePoint list title column
  3. DataCardValue9 = Text-input control name
  4. Supplied Product = SharePoint list choice column name
  5. DataCardValue10 = Combo box control name
  6. Is Paid Or Not = SharePoint list yes/no column name
  7. DataCardValue12 = Radio control name
  8. Product Supplied Date = SharePoint list date column name
  9. DataCardValue13 = Date-picker control name
How to Remove a first character from string using SharePoint list in Power Apps
  • SavePublish, and Preview the app. The user will enter the form details, including the product id that starts with an company code [ACGH], and click the SUBMIT button.
Power Apps Remove first character from string using a SharePoint list
  • Go to the specific SharePoint list and refresh it. You will view the new record that the Product ID will remove the first character of the string, as shown below:
Remove Power Apps first character from string using SharePoint list

This is how to remove the first character from a SharePoint list text field.

Conclusion

The above steps explained how to remove the first character from a string in Power Apps with different scenarios.

I hope you found this Power Apps tutorial helpful.

Additionally, you may like some more Power Apps articles: