Board index » delphi » Problem with accessing array strings characters

Problem with accessing array strings characters

Hi I am new to programming.

I have a problem with trying to access to an array of strings characters.

I have set up an array of 5 strings.  I want to get access to each of the
arrays individual characters.

i.e..  array[1] character 3

But I don't know how to do this.

The code I am Using is as follows.

sDescription := sDescription + asDscrip[nIndex1][nIndex2];

where
sDecription     is a string that I want to add to.
asDscrip          is the array.
nIndex1         is the array number
nIndex2           is the Character that I wish to add.

Can any one help me.

Patrick Matthews
patr...@pm-matt.freeserve.co.uk

 

Re:Problem with accessing array strings characters


Quote
Patrick Matthews wrote:
> Hi I am new to programming.

> I have a problem with trying to access to an array of strings characters.

> I have set up an array of 5 strings.  I want to get access to each of the
> arrays individual characters.

> i.e..  array[1] character 3

> But I don't know how to do this.

> The code I am Using is as follows.

> sDescription := sDescription + asDscrip[nIndex1][nIndex2];

> where
> sDecription     is a string that I want to add to.
> asDscrip          is the array.
> nIndex1         is the array number
> nIndex2           is the Character that I wish to add.

> Can any one help me.

The following works fine for me:

{$apptype console}

var
  i, nIndex1, nIndex2: Byte;
  asDescrip: array[1..5] of string;
  sDescrip: string;

begin
  asDescrip[1]:='abcde';
  asDescrip[2]:='fghij';
  asDescrip[3]:='klmno';
  asDescrip[4]:='pqrst';
  asDescrip[5]:='uvwxyz';
  sDescrip:='';
  for i:=1 to 5 do
    begin
      nIndex1:=Random(5)+1;
      nIndex2:=Random(5)+1;
      sDescrip:=sDescrip+asDescrip[nIndex1][nIndex2]
    end;
  Writeln(sDescrip)

end.

What happens when you try it?

Re:Problem with accessing array strings characters


In article <86hun3$pb...@newsg3.svr.pol.co.uk>, "Patrick Matthews"

Quote
<patr...@pm-matt.freeserve.co.uk> writes:
>I have set up an array of 5 strings.  I want to get access to each of the
>arrays individual characters.

>i.e..  array[1] character 3

>But I don't know how to do this.

>The code I am Using is as follows.

>sDescription := sDescription + asDscrip[nIndex1][nIndex2];

  sDescription := sDescription + asDscrip[nIndex1, nIndex2];

... but don't forget that nIndex2 must be 1 based.

The obvious is often possible <g>.

Alan Lloyd
alangll...@aol.com

Other Threads