Jump to content
twenty_sleven

Out of Range

Recommended Posts

Trying to concat certain values of an array of strings with a string, yet I continue to get the message "out of range", any help?

 

 

program HelloWorld;
var
i: Integer;
str: String;
aRay: array of string;
begin
str:= 'Hello';
aRay := ['W','o','r','l','d','!'];
for i := 0 to Length(aRay) do
   str:= str + aRay[i];
end.
//str := str +'World!';
 WriteLn(str+);
end.

Link to comment
Share on other sites

[scar]program HelloWorld;

var

i: Integer;

str: string;

aRay: array of string;

begin

str := 'Hello';

aRay := ['W', 'o', 'r', 'l', 'd', '!'];

for i := 0 to Length(aRay) - 1 do

str := str + aRay;

WriteLn(str);

end.[/scar]

 

You're looping from 0 to the Length, Length returns the number of values in the array, not the index of the largest item, the index is equal to the result of High or Length - 1.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...