program StartsWithSubstringFromArray;
function StartsWith(const str, prefix: string): Boolean;
begin
// Check if the string str starts with the prefix
StartsWith := Copy(str, 1, Length(prefix)) = prefix;
end;
function StartsWithAny(const str: string; const substrings: array of string): Boolean;
var
substring: string;
begin
for substring in substrings do
begin
if StartsWith(str, substring) then
begin
StartsWithAny := True;
Exit;
end;
end;
StartsWithAny := False; // Return False if no substring matches
end;
var
str: string;
substrings: array[0..4] of string;
begin
str := 'abcdefg';
// Array of substrings
substrings[0] := 'xy';
substrings[1] := 'poq';
substrings[2] := 'mnop';
substrings[3] := 'abc';
substrings[4] := 'rsuvw';
// Check if the string str starts with any substring from the array
if StartsWithAny(str, substrings) then
Writeln('The string starts with a substring from the array.')
else
Writeln('The string does not start with any substring from the array.');
end.
(*
run:
The string starts with a substring from the array.
*)