How to merge 2 string array in Delphi

后端 未结 3 1092
有刺的猬
有刺的猬 2021-01-04 20:11

I have 2 or more dynamic string array that fill with some huge data , i want to merge this 2 array to one array , i know i can do it with a for loop like this :



        
3条回答
  •  时光取名叫无心
    2021-01-04 20:40

    An excellent maxim is that the fastest code is that which never runs. Since copying is expensive you should look to avoid the cost of copying.

    You can do this with a virtual array. Create a class which holds an array of array of string. In your example the outer array would hold two string arrays.

    • Add a Count property that returns the total number of strings in all of the arrays.
    • Add a default indexed property that operates by working out which of the outer arrays the index refers to and then returns the appropriate value from the inner array.
    • For extra points implement an enumerator to make for in work.

提交回复
热议问题