Concatenate Matrix x Vectors

Asked

Viewed 79 times

3

I have the following values in a Stringlist :

 1111,2222
 3333,4444

I have another String list with values

 7777,8888
 9999,0000

I need to add the values of the second stringlist, concatenating at the same position in sequence of the first Example :

 1111,2222,7777,8888
 3333,4444,9999,0000

How do I add the content of the second data matrix in the first ?

  • Do you want to create a new list or change the first one? The two lists always have the same number of rows?

2 answers

1

You will need to get before which list, I mean the one that has the most data, otherwise it will occur violation or List of Bounds.

  for i := 0 to Pred(vLista1.Count) do
  begin
    vLista1.Strings[i] := vLista1.Strings[i] + ',' + vLista2.Strings[i];
  end;

This way we are editing the First List with the data of the Second in exactly the same order as the data.

0

See if it helps you

var
 oSL1: TStringList;
 oSL2: TStringList;
 iCont1,iCont2: Integer;
 sValor: String;
begin
  oSL1 := TStringList.Create;
  oSL2 := TStringList.Create;
  try
    oSL1.Add('1111,2222');
    oSL1.Add('3333,4444');

    oSL2.Add('7777,8888');
    oSL2.Add('9999,0000');

    for iCont1 := 0 to oSL1.Count-1 do
    begin
      for iCont2 := 0 to oSL2.Count-1 do          
        sValor := oSL1.Strings[iCont1]+','+oSL2.Strings[iCont2];
    end;
  finally
    FreeAndNil(oSL1);
    FreeAndNil(oSL2);
  end;
end;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.