procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
temp, SourceString, ResultString: string;
begin
temp := '';
ResultString := '';
SourceString := Memo1.Text;
for i := 1 to length(SourceString) do
begin
if SourceString[i] = ' ' then
begin
if length(temp) = 5 and pos(temp, 'A') = 0 then
ResultString := ResultString + temp + ', ';
temp := '';
continue;
end;
temp := temp + SourceString[i];
end;
ResultString := copy(ResultString, 1, length(ResultString) - 2);
end;