Looks for a pattern in a string.
bFound = MatchStr (sPattern, sString [, eCaseSensitivity, eEscapeWildcards])
| Variable | Description |
|---|---|
| bFound | Whether the pattern was found. BOOLEAN. |
| sPattern | The pattern to search for. STRING. |
| sString | The string to search. STRING. |
| eCaseSensitivity | Defines whether the pattern is case sensitive or not.
Default is CS_CASE_INSENSITIVE. ENUM. |
| eEscapeWildcards | Defines whether to enable escaping wildcard characters with a backslash (\) in the pattern to search for.
Default is EW_DISABLE_ESCAPE_WILDCARDS. ENUM. |
Use MatchStr to search through a file, a listing of menu contents, or other collection of strings for a pattern.
[-] testcase MatchStrExample()
[ ] LIST OF STRING lsFileNames // list of file names
[ ] INTEGER i // loop counter
[-] lsFileNames = {...}
[ ] "output.TXT"
[ ] "c:\windows\partner.ini"
[ ] "d:\dos\*.txt"
[ ] "result.out"
[ ] "test.res"
[ ] "*.TXT"
[ ]
[ ] // Print all file names that don't have a full path associated with them.
[-] for i = 1 to ListCount(lsFileNames)
[-] if (!MatchStr ("*:\*", lsFileNames[i]))
[ ] Print("File has no path: ", lsFileNames[i])
[ ] Print()
[ ]
[ ] // Print all file names with a TXT extension
[-] for i = 1 to ListCount(lsFileNames)
[-] if (MatchStr ("*.txt", lsFileNames[i], CS_CASE_INSENSITIVE))
[ ] Print("Filename with a TXT extension: ", lsFileNames[i])
[ ] Print()
[ ]
[ ] // Print all file names with an uppercase TXT extension
[-] for i = 1 to ListCount(lsFileNames)
[-] if (MatchStr("*.TXT", lsFileNames[i], CS_CASE_SENSITIVE))
[ ] Print("Filename with an uppercase TXT extension: ", lsFileNames[i])
[ ] Print()
[ ]
[ ] // Print all file names that contain an asterisk
[-] for i = 1 to ListCount(lsFileNames)
[-] if (MatchStr("*\**", lsFileNames[i], CS_CASE_INSENSITIVE, EW_ENABLE_ESCAPE_WILDCARDS))
[ ] Print ("Filename contains an asterisk: ", lsFileNames[i])
[ ] Print()
[ ]
[ ] // Print all file names that contain have an uppercase txt extension and contain an asterisk
[-] for i = 1 to ListCount(lsFileNames)
[-] if (MatchStr("*\**.TXT", lsFileNames[i], CS_CASE_SENSITIVE, EW_ENABLE_ESCAPE_WILDCARDS))
[ ] Print ("Filename contains an asterisk and uppercase TXT extension: ", lsFileNames[i])
[ ] Print()