#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    3
    Rep Power
    0

    comparing data in an array


    Hi I have a csv containing postcodes like this:

    "Perth", 6666
    "Melbourne", 7777
    \
    etc.

    I have loaded these values into an array like so.

    var
    i : integer;
    s : string;
    my_postcodes: TStringList;

    begin
    assign(myfile,'postcodes.csv');
    reset(myfile);
    my_postcodes := TStringList.Create;

    while not eof(myfile) do
    begin
    readln(myfile, line);
    my_postcodes.DelimitedText := line;


    for i := 0 to my_postcodes.Count - 1 do
    begin
    s := my_postcodes.Strings[i];
    s := my_postcodes[i]; // Same as previous line
    end;

    end;


    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.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    Hungary
    Posts
    43
    Rep Power
    11
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    5
    Rep Power
    0
    Hello.

    If you use a TStringList you have the IndexOf and the Find methods to locate in the list.

    Miguel

IMN logo majestic logo threadwatch logo seochat tools logo