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