"Для разработчиков", "Серверные скрипты", "Описание функций", "Разное", "SetArrayLength".
Указать размер динамического одномерного массива.
procedure SetArrayLength(var Arr: <dynamic array>; iNewLength: integer);
Параметр |
Тип |
Значение |
---|---|---|
Arr |
array of... |
одномерный массив любого типа; |
iNewLength |
integer |
количество элементов массива. |
Нумерация элементов массива будет от 0 до iNewLength - 1. Программа подсчитывает количество уникальных слов в тексте и выводит их в консоль:
const
ORIGINAL_TEXT = 'Take me, I''m alive, never was a girl with a wicked mind'#13#10 +
'But everything looks better, when the sun goes down'#13#10 +
'I had everything, opportunities for eternity and I'#13#10 +
'could belong to the night'#13#10 +
'Your eyes, your eyes, I can see in your eyes, your eyes';
var
sData, s: string;
iCount, i: integer;
Arr: array of string;
bAddFlag: boolean;
begin
mLogScript(ORIGINAL_TEXT, '');
sData := ReplaceString(LowerCase(ORIGINAL_TEXT), CRLF, ' ', true, false);
sData := ReplaceString(sData, ',', '', true, false);
iCount := 0;
SetArrayLength(Arr, 0);
while length(sData) > 0 do begin
s := Fetch(sData, ' ');
bAddFlag := true;
if iCount > 0 then
for i := 0 to iCount - 1 do
if Arr[i] = s then begin
bAddFlag := false;
break;
end;
if bAddFlag then begin
inc(iCount);
SetArrayLength(Arr, iCount);
Arr[iCount - 1] := s;
end;
end;
mLogScript('Unical words list:', '');
s := '';
for i := 0 to iCount - 1 do begin
s := s + Arr[i] + ' ';
if (i + 1) mod 10 = 0 then s := s + CRLF;
end;
mLogScript(s, 'Total ' + IntToStr(iCount) + ' words');
end.
[23:57:00] (Log "SetArrrayLength"): Take me, I'm alive, never was a girl with a wicked mind
But everything looks better, when the sun goes down
I had everything, opportunities for eternity and I
could belong to the night
Your eyes, your eyes, I can see in your eyes, your eyes
[23:57:00] (Log "SetArrrayLength"): Unical words list:
[23:57:00] (Log "SetArrrayLength"): [Total 35 words] take me i'm alive never was a girl with wicked
mind but everything looks better when the sun goes down
i had opportunities for eternity and could belong to night
your eyes can see in
[23:57:00] (Run "SetArrrayLength"): Время выполнения скрипта: 4 мс
[23:57:00] (Run "SetArrrayLength"): Скрипт выполнен успешно.