Let's say that we are interested in reading the file provided by the command line argument after the switch containing the replacement weights for the characters.
program WeightFileRead; uses SysUtils, StrUtils; var MyFile : TextFile; FirstChar, SecondChar, DummyChar : Char; Weight : Double; begin if GetCmdLineArg ('editweights', StdSwitchChars) = '' then begin WriteLn ('Syntax: WeightFileRead -editweights filename'); exit end; AssignFile (MyFile, GetCmdLineArg ('editweights', StdSwitchChars)); Reset (MyFile); try while not EOF (MyFile) do begin ReadLn (MyFile, FirstChar, DummyChar, SecondChar, Weight); WriteLn ('A: ', FirstChar, '; B: ', SecondChar, '; W: ', Weight:0:1); end finally CloseFile (MyFile) end end.
In a more general setting, when the first two entries may be longer lines, we can use ExtractWord , which finds the n th word separated by spaces in the line (or ExtractSubstr , which processes several spaces together as entering an empty word), and convert the third to number.
program WeightFileRead2; uses SysUtils, StrUtils; var MyFile : TextFile; FileLine : String; begin if GetCmdLineArg ('editweights', StdSwitchChars) = '' then begin WriteLn ('Syntax: WeightFileRead -editweights filename'); exit end; AssignFile (MyFile, GetCmdLineArg ('editweights', StdSwitchChars)); Reset (MyFile); try while not EOF (MyFile) do begin ReadLn (MyFile, FileLine); WriteLn ('A: ', ExtractWord (1, FileLine, [' ']), '; B: ', ExtractWord (2, FileLine, [' ']), '; W: ', StrToFloat (ExtractWord (3, FileLine, [' '])):0:1); end finally CloseFile (MyFile) end end.
Note. I use [' '] and not StdWordDelims since I don't want to. or to be a word separator.