CompareTextDiff function
Syntax
CompareTextDiff(new_text, old_text [, content_type [, delimiter]])
Description
Use the CompareTextDiff function to compare the content of new_text with the content of old_text and return an array of array of any detailing the differences between the two strings. The elements of the returned subarray are as follows:
| Element | Data Type | Description |
|---|---|---|
|
index |
number |
The sequential index number in the comparison array. |
|
line |
number |
The line number for the line of text being compared. |
|
subline |
number |
The subline is the counter of added lines that exist in the new_text. Note: For DELETE, CHANGED and COMMON operations, 0 is always reported for the subline. |
|
type |
string |
The type of difference:
|
|
text |
string |
The actual text being compared. |
Parameters
| Parameter | Description |
|---|---|
|
new_text |
Specifies the string that you want to compare with the old version of the string. |
|
old_text |
Specifies the old version of the string for comparison. |
|
content_type |
Specifies the content type as a literal: text or html. This parameter is optional. If content_type is html, HTML tags are stripped and are not included in the comparison. If content_type is not specified, it is set by default to text. |
|
delimiter |
An array of string specifying the delimiters to be used to split the content for comparison. This parameter is optional. If content_type is text and delimiter is not specified, the delimiter is set by default to char(13) (or \n, a carriage return). If content_type is html and delimiter is not specified, the delimiter array is populated by default with the following values:
|
Returns
An array of array of any.
Example
This example shows a comparison of two text strings. The variable &NewText contains the following string:
Line 2.
Line 2.1.
Line 2.2.
Line 3.
Line 5.
Line 6.
Line 8.
The variable &OldText contains the following string:
Line 1.
Line 2.
Line 3.
Line 4.
Line 7.
The following PeopleCode statement compares the two ASCII-formatted text strings, &NewText and &OldText:
&Output = CompareTextDiff(&NewText, &OldText, "text");
The string variable &Output contains the following array:
0, 1, 0, DELETED, Line 1.
1, 2, 0, COMMON, Line 2.
2, 2, 1, ADD, Line 2.1.
3, 2, 2, ADD, Line 2.2.
4, 3, 0, COMMON, Line 3.
5, 4, 0, CHANGED, Line 5.
6, 5, 0, CHANGED, Line 6.
7, 5, 1, ADD, Line 8.
Related Topics