comparing data in an array
Hi I have a csv containing postcodes like this:
I have loaded these values into an array like so.
i : integer;
s : string;
my_postcodes := TStringList.Create;
while not eof(myfile) do
my_postcodes.DelimitedText := line;
for i := 0 to my_postcodes.Count - 1 do
s := my_postcodes.Strings[i];
s := my_postcodes[i]; // Same as previous line
Does anyone know how I can choose a certain field from the array i.e. If i want to know the postcode for perth, how do I extract that information from the array and put it into a variable. I am really stuck!! Any help appreciated.
For arrays you need to do almost everything yourself. Search can be done using a cycle. If you need to insert an item somewhere, you have to increase the array's length, shift all the items forward above the desired position, and finally put the new item in the array. Sounds a bit tough, but actually isn't.
If you use a TStringList you have the IndexOf and the Find methods to locate in the list.