home *** CD-ROM | disk | FTP | other *** search
- { ************************************************************ }
- { This function is very useful if you manipulate a lot of CP/M }
- { comma delimited text files. It takes embedded commas into }
- { consideration by enclosing the substring in quotes ("). }
- { EXAMPLE: 'string,Albuquerque, NM,string' would show up in the}
- { file as: 'string,"Albuquerque, NM",string'. It takes care of }
- { reading the following comma so you are set to read the next }
- { file variable. If you have fixed length fields mixed with }
- { variable length fields you MUST read the following comma your}
- { self. EXAMPLE read(filename,filevar,ch) where filename is the}
- { file name, filevar is a file variable of fixed length and ch }
- { is of type String[1]. }
- { The function is called in the following manner: }
- { ****** VariableName:=Readvar(VariableName); ***** }
- { Global declaration : }
- { type Str40: String[40]; }
- { Written for Turbo Pascal Ver. 2, but it should work on any }
- { compiler. Steve Davis 8/21/84 }
-
- Function ReadVar(Var TempVar: Str40):Str40;
- Var
- Ch: Char;
- begin
- TempVar:=''; { Get Rid of any Garbage }
- If not Eoln(FileVar) then { If Not Eoln Read a char }
- begin
- Read(FileVar,Ch); { Read a character }
- If Ch = '"' Then { Test for First quote }
- begin
- Read(FileVar,Ch); { Read Until the Second }
- Repeat { Quote is Read in }
- TempVar:=TempVar+Ch; { Update TempVar }
- Read(FileVar,Ch) { Read Next Character }
- Until Ch = '"'; { End Repeat " }
- TempVar:='"'+TempVar+'"'; { Put the quotes back to write }
- { it back to a file. }
- If Ch='"' then
- Read(FileVar,Ch) { If " then read the comma }
- end
- Else If Ch <> Comma then { Else Read Until A Comma }
- Repeat { is Encountered }
- TempVar:=TempVar+Ch;
- Read(FileVar,Ch)
- Until (Ch = Comma) or (Eoln(FileVar));
- end;
- ReadVar:=TempVar { Assign the string. If the next ch was a comma }
- { TempVar:= ''. ie ,string,,string, }
- end; { Function ReadVar }