CommonPrefix

STD.Str.CommonPrefix( s1, s2 [ ,nocase ] )

STD.Uni.CommonPrefix( s1, s2 [ ,nocase ] )

s1A string to compare.
s2A string to compare.
nocaseOptional. If TRUE, the comparison is case-insensitive. If omitted, the default is FALSE.
Return:CommonPrefix returns either a STRING or UNICODE value, as appropriate. It contains the longest prefix common to both strings, as copied from the first argument. The result is empty if the strings have no common prefix or if either argument is empty.

The CommonPrefix function returns the longest prefix common to both strings. This can be used for identifying shared prefixes between strings, which can be helpful in text processing tasks such as pattern matching, data normalization, or linguistic analysis.

Example:

IMPORT Std;
Std.Str.CommonPrefix('DANIEL', 'DANNY',nocase:=FALSE); // DAN
Std.Str.CommonPrefix('DANIEL', 'Danny',FALSE);         // D
Std.Str.CommonPrefix('DANIEL', 'Danny',TRUE);          // DAN
Std.Str.CommonPrefix('APPLES', 'ORANGES',FALSE);       // empty 

See Also: CommonSuffix