How to perform the procedure of removing element from array by index?

There
Code
akb program;
procedure DeleteElem<T>(a: array of T; k: word); 
begin 
for var i := k - 1 to length(a) - 2 do 
a[i] := a[i + 1]; 


SetLength(a, length(a) - 1); 

for var i := 0 to length(a) - 1 do 
write(a[i] + ' '); 

end; 

var
text:string;
k:integer;

begin 

 write ('Enter text: ');
phony(text);

 var arr := text.Split(' '); // String is split into words on whitespace
 //writeln(arr[0], ' ', arr[3]); // Слово11 Слово22
 write ('Enter element to delete: ');
phony(k);


writeln('Array after processing: '); 
DeleteElem(arr, k); 
end.
.
Pascal ABC, everything is fine
works
5e280ab68e183732947485.png
.
But I need to run it in Turbo Pascal and that's what it
out
5e280afc6c597154987970.png

I need to work on turbo Pascal, you need to change in the code?
The original task.
Given the text up to 255 characters. Words are separated from each other by spaces. To remove from the text the words with these rooms.
April 4th 20 at 13:18
1 answer
April 4th 20 at 13:20
Solution
You inicializirati variable right in the loop. This can not TP.
Well, judging by the instructions, don't forget that you have shifted to words and the word indexes do not match.
So it is enough to specify the variables in the beginning and all? - madisyn_Daniel1 commented on April 4th 20 at 13:23
can you help? - madisyn_Daniel1 commented on April 4th 20 at 13:26
@madisyn_Daniel1, Yes, declare them as usual. - lemuel3 commented on April 4th 20 at 13:29
@lemuel3, I don't know how) on this Pascal)) - madisyn_Daniel1 commented on April 4th 20 at 13:32
@lemuel3, help me pls - madisyn_Daniel1 commented on April 4th 20 at 13:35
@madisyn_Daniel1, just before you begin
procedure DeleteElem<T>(a: array of T; k: word); 
var i: integer;
begin 
for i := k - 1 to length(a) - 2 do 
a[i] := a[i + 1]; 
....
- lemuel3 commented on April 4th 20 at 13:38
@madisyn_Daniel1, well, you got the Split won't work of course. - lemuel3 commented on April 4th 20 at 13:41
@madisyn_Daniel1you do not delete elements from the array. Just do an empty string.
So you will keep the corresponding indexes of words. And then convert the array to text, ignoring empty elements of the array. - lemuel3 commented on April 4th 20 at 13:44
@lemuel3, are there any analogues of split? - madisyn_Daniel1 commented on April 4th 20 at 13:47
@lemuel3, 5e280fcbd46e4189486654.png - madisyn_Daniel1 commented on April 4th 20 at 13:50
@madisyn_Daniel1, I'm thrown off like you do in the question - lemuel3 commented on April 4th 20 at 13:53
@lemuel3, I looked but could not catch up( will be able to make it work?
that is the problem
Given the text up to 255 characters. Words are separated from each other by spaces. To remove from the text the words with these rooms.
.
My implementation does not fit the TP, just need it. Help pls! - madisyn_Daniel1 commented on April 4th 20 at 13:56
@madisyn_Daniel1,
program changes from split1;

var
 InputStr, AWord: string;
 i, j, SpaceCount, LastPos, LastIndex: integer;
 a: array of string; 
 DelItems: array of integer;

begin
 InputStr := '1 2 3 4 5 6 7 8 9 0';

WriteLn(InputStr);
 //Something to remove
 SetLength(DelItems, 3);
 DelItems[0] := 2;
 DelItems[1] := 5;
 DelItems[2] := 7;

 //Clean extra white space on the edges
 InputStr := Trim(InputStr);
 for i := 1 to Length(InputStr) do
 if InputStr[i] = '' then Inc(SpaceCount);
 //Size of array
 SetLength(a, SpaceCount + 1);
//Cleanup
 LastPos := 1;
 LastIndex := 0;
 AWord := ";
 //Cycle
 for i := 1 to Length(InputStr) do
begin
 if InputStr[i] <> '' then 
 AWord := AWord + InputStr[i];
 if (InputStr[i] = ' ') or ((i + 1) > Length(InputStr)) then
begin
 if AWord <> " then
begin
 a[LastIndex] := AWord;
Inc(LastIndex);
 LastPos := i;
 AWord := ";
end;
end;
 end; 
//Delete
 for i := 0 to Length(a) - 1 do
 for j := 0 to Length(DelItems) - 1 do
 if i = DelItems[j] then
 a[i] := ";
//Print
 for i := 0 to Length(a) - 1 do 
 if a[i] <> " then
 write(a[i], ' ');
end.
- lemuel3 commented on April 4th 20 at 13:59

Find more questions by tags Pascal