Two approaches to replace all occurrences of a value in a String using SharePoint list formatting: replaceAll & split + join


Until some time ago there was only a replace function in list formatting, which allowed us to replace only the first occurrence of a value in a string.

Recently Microsoft released two new operators for list formatting:

  • replaceAll
  • split

With the replaceAll we can easily replace with all occurrences of a value in a string as in the example below, where we replace client by customer:

replaceAll has 3 parameters: field, original value, replacement value

replaceAll('fullString','value','replacement')

Sample JSON:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "span",  
  "txtContent": "=replaceAll([$Title],'client','customer')"
}

Result (used in the Updated Text field):

The split operator accepts as a parameter a string and a value to split it:

=split('fullString','valueToSplit')

It outputs an array with the results, so for example, the below expression:

=split('A client trip to meet...

Source link

More About This Author

michelcarlo
michelcarlo
SharePoint and Office 365 Consultant/Developer always trying to get the best from Microsoft stack (Microsoft 365/Azure/Power Platform and related stuff).

Living in Ireland since 2018, I had previously worked in Brazil as a consultant/developer for Office 365, SharePoint and related technologies for almost 10 years.

Author: michelcarlo

SharePoint and Office 365 Consultant/Developer always trying to get the best from Microsoft stack (Microsoft 365/Azure/Power Platform and related stuff). Living in Ireland since 2018, I had previously worked in Brazil as a consultant/developer for Office 365, SharePoint and related technologies for almost 10 years.

Share This Post On
Share via
Copy link
Powered by Social Snap