defjam90
21st September 2008, 10:56
I would like to read a comma seperated file .
Here is a sample of the file
Order No,Order Pos,Order Currency,PO Qty,Receipt Qty,Price
200058,2,SGD,20,20,25.50000
200519,4,USD,4,4,6.00000
200632,2,USD,2,2,6.00000
200669,1,USD,14,14,6.00000

Each field is seperated by comma & I would like to hold each of these in variables
Ex Var a = 200058
b= SGD

I can use the function POS/RPOS to find out the comma & then read the string this is tedious process.

Is there any other simple way of reading the string.If so please provide the syntax.

Thanks

garima
21st September 2008, 15:37
Hi
You can use the string.scan and seq.gets function to read Comma separated file

#define SCANS "%s,%s,%s,%s,%s

#define FIELDS fld1,fld2,fld3,fld4,fld5
function main()
{
long fp
string a(12)
string b(12)
string buffer(80)
fp = seq.open("filename", "r")
while not seq.gets(buffer, 1024, fp)
string.scan(buffer,SCANS,FIELDS)
endwhile
e = seq.close(fp)
}

defjam90
22nd September 2008, 04:19
Thanks for the feed back.
I am getting a compile error with this function
string.scan(msg.str,SCANS,FIELDS)

Based on your systax how does the system know that "," is the seperator.


Thanks

vinceco252
22nd September 2008, 05:29
In the example, "%s,%s,%s,%s,%s", it knows that the comma is the delimeter because there are commas between the arguments "%s". So if you used "%s|%s|%s|%s|%s" it would expect you to pass a statement using "|" as the separator...

Vince

bdittmar
22nd September 2008, 14:01
I would like to read a comma seperated file .
Here is a sample of the file
Order No,Order Pos,Order Currency,PO Qty,Receipt Qty,Price
200058,2,SGD,20,20,25.50000
200519,4,USD,4,4,6.00000
200632,2,USD,2,2,6.00000
200669,1,USD,14,14,6.00000

Each field is seperated by comma & I would like to hold each of these in variables
Ex Var a = 200058
b= SGD

I can use the function POS/RPOS to find out the comma & then read the string this is tedious process.

Is there any other simple way of reading the string.If so please provide the syntax.

Thanks

Hello,

your fields are long,long,string,double,double,double

so your scan should be:

%d,%d,%s,%f,%f,%f

Regards