s1
- string; arr
- array
s1:=arr[i]+' '; write(f,s1);
This is where the problem is at the end of the line is a space after the last element. How to fix?
If the array indices start at 1, then fix it like this:
s1 := ''; for i := 1 to arrLength - 1 do // добавим все, кроме последнего, ... s1 := s1 + arr[i] + ' '; // ... с пробелом s1 := s1 + arr[arrLength]; // добавим последний без пробела write(f, s1); // запишем результат
Inside the loop, check whether the last element is or not:
for i := 1 to arrLength do begin if i < arrLength then s1:=arr[i] + ' '; else s1:=arr[i]; end
s1:=arr[i];
in any case ... but below write if i < arrLength then s1:= s1 + ' ';
- Alexey ShimanskySource: https://ru.stackoverflow.com/questions/476163/
All Articles
trim
- Alex Shimansky