Searching a substring in a string list that has delimiters between its elements.
function IsStringInList(sWhat, sStringList, sDelimiter: string; bIgnoreCase: boolean): boolean;
Parameter |
Type |
Value |
---|---|---|
sWhat |
string |
substring that you need to find; |
sStringList |
string |
source string for searching; |
bIgnoreCase |
boolean |
true — ignore the letter case, false — the difference between letters case does not matter. |
Most MSL functions, which return a text string with a list of elements, have the "|" symbol as the delimiter. However, you can use any delimiters both from one or several symbols.
True, if the specified element exists in the source string between delimiters.
const
sFirst = 'Blue|Red|Green|';
sSecond = 'John Carpenter,Ivan Dulin,Sara Connor';
begin
mLogScript('Original string "' + sFirst + '"', '');
if IsStringInList('red', sFirst, '|', true) then mLogScript('"red" found', '')
else mLogScript('"red" not found', '');
mLogScript('Original string "' + sSecond + '", case sensitive search', '');
if IsStringInList('sara connor', sSecond, ',', false) then mLogScript('"sara connor" found', '')
else mLogScript('"sara connor" not found', '');
end.
[16:08:24] (Log "IsStringInList"): Original string "Blue|Red|Green|"
[16:08:24] (Log "IsStringInList"): "red" found
[16:08:24] (Log "IsStringInList"): Original string "John Carpenter,Ivan Dulin,Sara Connor", case sensitive search
[16:08:24] (Log "IsStringInList"): "sara connor" not found