How do I check whether a string exists in an array?
As you have found you can't check for a String in an Array of String, using in
.
You could use this function instead of the if
statement.
function StrInArray(const Value : String;const ArrayOfString : Array of String) : Boolean;
var
Loop : String;
begin
for Loop in ArrayOfString do
begin
if Value = Loop then
begin
Exit(true);
end;
end;
result := false;
end;
You can call it like this.
if StrInArray(ExtString,Extensions) then
The StrUtils.pas
has this already defined.
function MatchStr(const AText: string; const AValues: array of string): Boolean;
Initialise a TStringList instance from the constant array and use IndexOf().