Search code examples
lazarus

Extracting specific points of a .txt in lazarus


I have a textfile and I want to extract a specific value of it for example I have a line:

002345,6,7,8,9,10,25,

and I just want the values 7 9 and 25 to get extracted. I don't seem to find a way to get this working and I thought someone might be able to help me. PS: I'm programming on Lazarus


Solution

  • The following code:

    uses
      strutils;
    var
      seq, v1, v2, v3: string;
    begin
      seq := '002345,6,7,8,9,10,25,';
      v1 := ExtractWord(3, seq, [',']);
      v2 := ExtractWord(5, seq, [',']);
      v3 := ExtractWord(7, seq, [',']);
      writeln('3º: ', v1);
      writeln('5º: ', v2);
      writeln('7º: ', v3);
    end.
    

    will output:

    3º: 7
    5º: 9
    7º: 25