## Compare strings

2
Hi I am looking to build a microflow that will help me identify the changes between two strings. the basic case would be: string New = Han Pieter string Old = Han Difference between old and new = Pieter how can I compare two strings and identify the differences between the two?
3

This is one of the harder things in computer science so I recommend using a library for this. For example, have a look at http://en.wikipedia.org/wiki/Levenshtein_distance for a possible algorithm to use. There are many more like this, including combinations.

Unless you're always certain that just a piece of text is put after the original string, then it's fairly easy. Also see https://world.mendix.com/display/refguide3/String+function+calls. Just check if the original string is present with 'contains' or 'find' and then read the rest of the string from that position to the end. This is an extremely simple case though, for anything more complex you really should use libraries.

0

First check which of the strings is longer with the length(\$string) check. Then do a find(\$stringLongest,\$stringShortest). If it is -1 then the strings do not match, otherwise store the result in an integer value \$startposition-stringShortest. The last part is doing a substring(\$stringLongest,0, \$startposition-stringShortest).

Regards,

Ronald

0

Step 1: Create an empty string and call it \$difference.

Step 2: Determine the the length of both strings by using length, let's call this variable (integer) \$lengthold and \$lengthnew.

Step 3: For each character until min(\$lengthold, lengthnew), compare \$oldstring to \$newstring by using substring(x,teller,1). If the same, add an space (' ') to \$difference. If different add \$newstring's character to \$difference.

Step 4: If \$lengthold > \$lengthnew add a space (' ') to \$difference. Once for each character (eg. \$lengthold-\$lengthnew = 4 --> ' '). If \$lengthnew > \$lengthold add the remainder of \$newstring to \$difference by using substring.

Eg. \$oldstring = John. \$newstring = Mohammed --> \$lengthold = 4, \$lengthnew = 8. Iterating through all steps will return 'M ammed'.

Eg. \$oldstring = Mohammed. \$newstring = John. --> will return: 'J n '.