cancel
Showing results for
Did you mean:
Helper I

## Two strings comparison and find out different strings

Hi there,

I have questions is find out different part between two strings. For instance, One sting is "/sites/A/B/C/D", another string is "/sites/A/B/C/D/E/F/G/H". I would like to find out the different string "/E/F/G/H". I would like to know if there is any way to find it. Would you all have any ideas on it?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Frequent Visitor

String manipulation methods can be used to determine the difference between two strings. In your case, you can separate the two strings with "/" and then compare them element by element until you find the first one that differs. The difference would be the elements following the different element in the second string.

Here's an example of a Power Automate implementation using Javascript&colon;

``````// Define the two strings
var string1 = "/sites/A/B/C/D";
var string2 = "/sites/A/B/C/D/E/F/G/H";

// Split the strings into arrays
var array1 = string1.split("/");
var array2 = string2.split("/");

// Find the difference
var difference = "";
for (var i = 0; i < array2.length; i++) {
if (array1[i] !== array2[i]) {
difference = "/" + array2.slice(i).join("/");
break;
}
}

// Log the difference
console.log(difference);``````

This code will return "/E/F/G/H," which represents the difference between the two strings.

Frequent Visitor

String manipulation methods can be used to determine the difference between two strings. In your case, you can separate the two strings with "/" and then compare them element by element until you find the first one that differs. The difference would be the elements following the different element in the second string.

Here's an example of a Power Automate implementation using Javascript&colon;

``````// Define the two strings
var string1 = "/sites/A/B/C/D";
var string2 = "/sites/A/B/C/D/E/F/G/H";

// Split the strings into arrays
var array1 = string1.split("/");
var array2 = string2.split("/");

// Find the difference
var difference = "";
for (var i = 0; i < array2.length; i++) {
if (array1[i] !== array2[i]) {
difference = "/" + array2.slice(i).join("/");
break;
}
}

// Log the difference
console.log(difference);``````

This code will return "/E/F/G/H," which represents the difference between the two strings.

Announcements

#### Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!