<< Click to Display Table of Contents >> Navigation: 3. Script Language > String commands > !STR.- String Command > String Operations |
MiniRobotLanguage (MRL)
STR.FindBestMatch
Find the best match for a given string in a list of strings using Levenshtein distance, return a number.
Intention
The STR.FindBestMatch command is used to find the closest matching string in a list of strings to a given string.
The command uses the Levenshtein distance algorithm for string comparison.
The result will be the number corresponding to the best match in the list or -1 if an error occurs.
The result will be placed in an optional variable P3 or on TOS if the variable is omitted.
Syntax
STR.FindBestMatch|P1|P2[|P3]
STR.FBM|P1|P2[|P3]
Parameter Explanation
•P1 - (List, Text) Variable containing a comma or semicolon-separated list of strings. Each string can optionally start with a numeric value between 0 and 9999, followed by either a "." or a "-" and any number of spaces. The numeric value can be missing.
•P2 - (Target, Text) Variable containing the string to compare against the list.
•P3 - (Output, Numeric) Optional variable to store the result. If omitted, the result is placed on TOS.
Example
'*************************************
' STR.FindBestMatch
'*************************************
VAR.$$LIS="1. apple,2. orange,3. banana"
VAR.$$TAR="orenge"
STR.FindBestMatch|$$LIS|$$TAR|$$RES
DBP.Best Match: $$RES
' Result is 2
ENR.
Remarks
-
Limitations:
-
See also:
• 1.5.2 Working with Text-Strings
• VAR. - Variable Set Value/Clear
• IVS. / NVS. - If-Variable-String
• SBD. - String between Delimiter
• SBM. - String between Delimiter-Multiple