get differences
This function checks two strings for deviating contents and copies them in two substrings.
In detail, the function scans the two strings character by character from left to right until a position with different characters have been identified.
The same will be repeated with scanning from the end of both strings leftward until a first difference is encountered.
The middle contents are deemed different, even if only the first and last character(s) are different, as in follwoing example:
Example 1: Checking: "The yak is blond" and "The jak is blind".Deltas are: "yak is blo" and "jak is bli".
Example 2: Checking: "The yak is blond" and "The jak is blond".Deltas are: "y" and "j".
Options are available to include whole words or numbers in the comparison, so "My name is Jan". / "My name was Dan." will preserve the name.
Indirect parameter passing is disabled
2-5
No. | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
1 input |
string | 1st string 1st string to compare with 2nd string | ||||||||
2 input |
string | 2nd string 2nd string to compare with 1st string | ||||||||
Opt. 3 output |
string | Deviating part of 1st string Identified part of the 1st string which differs from the part of the 2nd string | ||||||||
Opt. 4 output |
string | Deviating part of 2nd string Identified part of the 1st string which differs from the part of the 2nd string | ||||||||
Opt. 5 input |
string | Options Following options apply:
Default value: characters |
Type | Description |
---|---|
numeral | Comparison result 0 = The two strings are equal |
r[] = get differences(Good taste of coffee counts, Good taste of coffee counts, c[], d[] );
echo("1st string: '", c[], "', 2nd string: '", d[], "' Result: ", r[] ); // '', '', 0 (equal)
r[] = get differences(Good taste of coffee counts, Good taste of caffè counts, c[], d[] );
echo("1st string: '", c[], "', 2nd string: '", d[], "' Result: ", r[] ); // offee, affè, 1
r[] = get differences(Good taste of coffee counts, Good taste of caffè counts, c[], d[], words );
echo("1st string: '", c[], "', 2nd string: '", d[], "' Result: ", r[] ); // coffee, caffè, 3
r[] = get differences(Good taste of coffee counts, Good taste counts, c[], d[], words );
echo("1st string: '", c[], "', 2nd string: '", d[], "' Result: ", r[] ); // coffee, '', 2
r[] = get differences(Good tasting of coffee counts, Good taste of caffè counts, c[], d[], words );
echo("1st string: '", c[], "', 2nd string: '", d[], "' Result: ", r[] ); // tasting of coffee, taste of caffè, 3
r[] = get differences(Year 2015 begins, Year 2016 begins, c[], d[], characters);
echo("1st string: '", c[], "', 2nd string: '", d[], "' Result: ", r[] ); // 5, 6, 1
r[] = get differences(Year 2015 begins, Year 2016 begins, c[], d[], words);
echo("1st string: '", c[], "', 2nd string: '", d[], "' Result: ", r[] ); // 5, 6, 1
r[] = get differences(Year 2015 begins, Year 2016 begins, c[], d[], numbers);
echo("1st string: '", c[], "', 2nd string: '", d[], "' Result: ", r[] ); // 2015, 2016, 3
r[] = get differences( "20-Mar-2015", "21-Mar-2015" , c[], d[], characters);
echo("1st string: '", c[], "', 2nd string: '", d[], "' Result: ", r[] ); // 0, 1, 1
r[] = get differences( "20-Mar-2015", "21-Mar-2015" , c[], d[], spaces);
echo("1st string: '", c[], "', 2nd string: '", d[], "' Result: ", r[] ); // 20-Mar-2015, 20-Mar-2016, 1
1st string: '', 2nd string: '' Result: 0
1st string: 'offee', 2nd string: 'affè' Result: 1
1st string: 'coffee', 2nd string: 'caffè' Result: 3
1st string: 'of coffee ', 2nd string: '' Result: 2
1st string: 'tasting of coffee', 2nd string: 'taste of caffè' Result: 3
1st string: '5', 2nd string: '6' Result: 1
1st string: '5', 2nd string: '6' Result: 1
1st string: '2015', 2nd string: '2016' Result: 3
1st string: '0', 2nd string: '1' Result: 1
1st string: '20-Mar-2015', 2nd string: '21-Mar-2015' Result: 3