Title: How to abbreviate a full name?
Question: You possess your customer's full name in your database, but you wants to abbreviate the name of the same, use that function.
Answer:
function AbreviaNome(Nome: String): String;
var
Nomes: array [ 1..20 ] of string;
i, TotalNomes: Integer;
begin
Nome := Trim(Nome);
Result := Nome;
Nome := Nome + #32;
i := Pos(#32, Nome);
if i 0 then begin
TotalNomes := 0;
while i 0 do begin
Inc(TotalNomes);
Nomes[TotalNomes] := Copy(Nome, 1, i - 1);
Delete(Nome, 1, i);
i := Pos(#32, Nome);
end;
if TotalNomes 2 then begin
for i := 2 to TotalNomes - 1 do begin
if Length(Nomes[i]) 3 then
Nomes[i] := Nomes[i][1] + '.';
end;
Result := '';
for i := 1 to TotalNomes do
Result := Result + Trim(Nomes[i]) + #32;
Result := Trim(Result);
end;
end;
end;