Latest Posts

PowerApps check if string starts with specific sub string


The StartsWith function in PowerApps is used to determine whether a specified text string begins with a certain substring. This can be useful for filtering data, searching, or validating input fields.

PowerApps – StartsWith() function Syntax

StartsWith(Text, StartText)

 

  • Text: The text string to be tested.
  • StartText: The substring to check if it appears at the beginning of the Text.

Notes:

  • Empty Strings: If StartText is an empty string, StartsWith will always return true because every string starts with an empty string.
  • Case Sensitivity: StartsWith is case-insensitive. "PowerApps" and "powerapps" will both match "power".

·        Using StartsWith on large data sources can impact performance, especially if combined with other functions in complex filters. Consider optimizing your data source or using delegation where possible.

PowerApps – Basic Example of StartsWith() function

To check if the string "PowerApps" starts with "Power":

StartsWith("PowerApps", "Power")

This returns true because "PowerApps" does indeed start with "Power".

PowerApps – Check StartsWith() function using a Variable

Suppose you have a variable named MyText that holds a string value, and you want to check if it starts with "Hello":

StartsWith(MyText, "Hello")

 

PowerApps - Filter a Data Source column value, starts with string

Suppose you have a data source named Employees with a column Name, and you want to filter the employees whose names start with "J":

Filter(Employees, StartsWith(Name, "J"))

This returns a table of employees whose names start with the letter "J".

You can use the StartsWith function to implement a search box that filters items in a gallery. Suppose you have a gallery bound to a data source named Products and a text input control named SearchBox:

Filter(Products, StartsWith(ProductName, SearchBox.Text))

This filters the products to show only those whose ProductName starts with the text entered in the search box.

PowerApps - Validate Input string using StartsWith() function

If you want to ensure that a text input control starts with a specific prefix, you can use the StartsWith function in the OnChange property of the text input control:

If(Not(StartsWith(TextInput1.Text, "ABC")), Notify("Input must start with 'ABC'", NotificationType.Error))

This checks if the input starts with "ABC" and displays an error notification if it does not.

PowerApps – Search contact list where name starts with string

Suppose you have a contact list and you want to filter the list to show only contacts whose names start with the letter entered by the user:

  1. Add a Text Input Control for Search

Name the text input control SearchInput.

  1. Add a Gallery to Display the Contacts

Set the Items property of the gallery to:

Filter(Contacts, StartsWith(Name, SearchInput.Text))

 

This filters the contacts to show only those whose names start with the text entered in the SearchInput.


We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint