Awkwardsaw
2013-07-29 22:03:21
For some unknown reason the discussion using string as an array has popped up in the Skype group.
Through random experiments, I've noticed that if you run this:
it will result in something like
As if Simba automatically fills in the null elements. If you setlength() in the loop using "setlength(s, i + 1);" it will instead make the first element(s[1]) the length of the array,
resulting in:
And finally, if you remove setlength all together, the first element of 's' is actually the first element of the char array. This is probably common sense to everyone, but it strikes me as interesting, since I've never really messed with this. Thoughts?
Through random experiments, I've noticed that if you run this:
program new;
var
c : Array of Char;
s : string;
i : integer;
begin
c := ['h', 'e', 'l', 'l', 'o'];
s := '';
writeln(length(c));
setlength(s, length(c));
for i := 0 to 4 do
begin
s := s + c[i];
writeln(s);
end;
Delete(s, 1, 1);
writeln(s[1]);
end. it will result in something like
formWh
formWhe
formWhel
formWhell
formWhelloAs if Simba automatically fills in the null elements. If you setlength() in the loop using "setlength(s, i + 1);" it will instead make the first element(s[1]) the length of the array,
program new;
var
c : Array of Char;
s : string;
i : integer;
begin
c := ['h', 'e', 'l', 'l', 'o'];
s := '';
writeln(length(c));
for i := 0 to 4 do
begin
setlength(s, i + 1);
s := s + c[i];
writeln(s);
end;
end. resulting in:
5
5h
5he
5hel
5hell
5helloAnd finally, if you remove setlength all together, the first element of 's' is actually the first element of the char array. This is probably common sense to everyone, but it strikes me as interesting, since I've never really messed with this. Thoughts?