What is the fastest way to Parse a line in Delphi?

前端 未结 9 1972
深忆病人
深忆病人 2020-12-13 01:18

I have a huge file that I must parse line by line. Speed is of the essence.

Example of a line:

Token-1   Here-is-the-Next-Token      La         


        
9条回答
  •  悲&欢浪女
    2020-12-13 01:53

    The fastest way to write the code would probably be to create a TStringList and assign each line in your text file to the CommaText property. By default, white space is a delimiter, so you will get one StringList item per token.

    MyStringList.CommaText := s;
    for i := 0 to MyStringList.Count - 1 do
    begin
      // process each token here
    end;
    

    You'll probably get better performance by parsing each line yourself, though.

提交回复
热议问题