Board index » delphi » processing files w/tabs

processing files w/tabs

I have to process tab delimited files. So, each line (or record)
of a text file has fields separated by tabs. This is a popular
format for im/exporting to databases.

eg. 1st field -> 2nd filed ->.......eol
      1st field -> 2nd filed ->.......eol
      1st field -> 2nd filed ->.......eol
       eoF

ques.
how do say things like " while not tab do", if tab then do",
"writeln (outfile, tab)".?

how do i test, write, read a tab, to enable me to
process such a file? I would think a tab is just another
char but I am not sure.

Thanks

 

Re:processing files w/tabs


Well... The ordinal value of TAB is 9 so you can

 readln(f,tmpstr);
 i := pos(chr(9),tmpstr);
 count := 1;
 while i > 0 do begin
  column[count] := copy(tmpstr,1,i -1);
  delete(tmpstr,1,i);
  inc(count);
  i := pos(chr(9),tmpstr);
 end;
 column[count] := tmpstr {There will be 1 column left over}

And writeing is simple.
Work out how wide you want your columns, eg 12 characters wide;
for i := 1 to columncount do
 write(column[i]: 12);

I hope this helps

Shannon

Quote
leegold <leegoldno-s...@operamail.com> wrote in message

news:904mhc$3gm$1@bob.news.rcn.net...
Quote
> I have to process tab delimited files. So, each line (or record)
> of a text file has fields separated by tabs. This is a popular
> format for im/exporting to databases.

> eg. 1st field -> 2nd filed ->.......eol
>       1st field -> 2nd filed ->.......eol
>       1st field -> 2nd filed ->.......eol
>        eoF

> ques.
> how do say things like " while not tab do", if tab then do",
> "writeln (outfile, tab)".?

> how do i test, write, read a tab, to enable me to
> process such a file? I would think a tab is just another
> char but I am not sure.

> Thanks

Re:processing files w/tabs


On Wed, 29 Nov 2000 23:54:10 -0500, "leegold"

Quote
<leegoldno-s...@operamail.com> wrote:
>I have to process tab delimited files. So, each line (or record)
>of a text file has fields separated by tabs. This is a popular
>format for im/exporting to databases.

>eg. 1st field -> 2nd filed ->.......eol
>      1st field -> 2nd filed ->.......eol
>      1st field -> 2nd filed ->.......eol
>       eoF

>ques.
>how do say things like " while not tab do", if tab then do",
>"writeln (outfile, tab)".?

>how do i test, write, read a tab, to enable me to
>process such a file? I would think a tab is just another
>char but I am not sure.

>Thanks

Although I have not done this in Pascal, I have done exactly this in
another language. You're right, tab is just another char, Chr(9). I
suggest you use Pascal's BlockRead into an array of bytes (or chars).
This will place ALL the chars into the array including CR, LF and tab.
You can now scan the array and isolate the fields. By the way, you can
make the array handle 64K byte blocks.

If this is not clear, send me an email and I will send a brief demo.

Clif   <clifp...@airmail.net  

Re:processing files w/tabs


Quote
"Shannon Wynter" <fre...@southcom.com.au> wrote in message

news:904phg$bfc$1@corolla.OntheNet.com.au...

Quote
> Well... The ordinal value of TAB is 9 so you can

>  readln(f,tmpstr);

while pos(chr(9),tmpstr) >0 do delete(tmpstr,1,pos(chr(9)));

{I think this is a lot more efficent :) }

Quote
> And writeing is simple.
> Work out how wide you want your columns, eg 12 characters wide;
> for i := 1 to columncount do
>  write(column[i]: 12);

This is the same.

Quote
> I hope this helps

so do I.

Quote
> Shannon
> leegold <leegoldno-s...@operamail.com> wrote in message
> news:904mhc$3gm$1@bob.news.rcn.net...
> > I have to process tab delimited files. So, each line (or record)
> > of a text file has fields separated by tabs. This is a popular
> > format for im/exporting to databases.

> > eg. 1st field -> 2nd filed ->.......eol
> >       1st field -> 2nd filed ->.......eol
> >       1st field -> 2nd filed ->.......eol
> >        eoF

I can give you a unit if you want that will help you to process your file in
about 10 lines of code+my unit.. or a bit bigger with out the unit.. but I
like my unit as it's easy to understand and versatile enuff to use on pritty
much anything.
What do you want the output to look like? do you want to generate a text
file?
It'll take about five mins once you tell me what you want the output to be.

Quote
> > ques.
> > how do say things like " while not tab do", if tab then do",
> > "writeln (outfile, tab)".?
> > how do i test, write, read a tab, to enable me to
> > process such a file? I would think a tab is just another
> > char but I am not sure.

I don't need to say any more :)

Other Threads