norwim
10th July 2002, 11:26
Hi there,

I have a csv-file with 19 fields, seperated by ";".
What I try to do (and in fact did succesfully quite often) is to read this file and grab the fields with string.scan.
so I have string buf(512)
string d1(40)
string d3(40)
string d4(40)
string d6(40)
string d7(40)
string d8(40)
string d9(40)
string d10(40)
string d11(40)
string d12(40)
string d15(40)
string d18(40)
string d19(40)
plus the variables I actually need.
I read the file (seq.gets) into buf line by line.
When I do a
oki=string.scan(buf,"%s;%s;%s;%s;%s;s%;s%;s%;s%;s%;s%;s%;s%;s%;s%;s%;s%;
%s;%s",d1,mycuno,d3,d4,bbn,d6,d7,d8,d9,d10,d11,d12,telp,tefx,d15,fovn,bbnp,d18,d
19)
oki=6 and in fact d6 contains 40 byte including the ";" (seperator).
All other variables are empty.
buf contains about 300 bytes and I can see all the fields in debug mode(in buf). There is no CR or suchlike in buf.

I counted and recounted - the file should contain 19 fields, the mask for string.scan contains 19 "%s;"


Anyone any idea??

thanks in advance
Norbert

mark_h
10th July 2002, 14:35
Check the file out with a text editor - make sure the file does not have any quotes(") in it. I have seen string.scan do this when a " got into the file. Usually I saw something like xx,"y,zz. then the y,zz would come in as one field. Our users actually used "'s in descriptions. This caused a lot of headaches when reading csv files.

Good Luck!

Mark

norwim
10th July 2002, 16:39
Thanks a lot Mark -

the problem was that I messed up the format string:
I wrote "s%" instead of "%s"
:-(
shame on me, I should have read instead of merely count

But, to be fair, at least the Fax-gateway (Baan to hylafax) is up and running (this cost less time than this "bug") - so this day after all was a good one!

Thanks again

Norbert

Dwallace
13th January 2003, 22:46
I have a comma delimited file with quotes around the strings. I want to eliminate the quotes when running the string.scan().

Possible?

D

NPRao
13th January 2003, 23:25
Hi Denise,

Yes you can do that.

Here is an example program -

function main()
{
long fp
string a(12)
string b(12)
string buffer(80)
fp = seq.open("np", "r")
while not seq.gets(buffer, 1024, fp)
i = string.scan(buffer, """%s"", ""%s""", a, b)
endwhile
e = seq.close(fp)
}

Here are contents on my test file "np"-

$ cat np
"Hello","world"
$

If you can see the values of a and b variables in debugger you can see they are without the quotes.

But my suggestion would be to use the find and replace function from the tools dll - ottdllstring
void search.and.replace( ref string line(), const string srch(), const string replace() )

we can use it easily as search.and.replace(buffer, """", "") or
instead of getting confused with some many quotes... or you can also use the quoted.string().

I am not sure if you have this dll/function in your BaaN Version.

Good Luck!

Dwallace
13th January 2003, 23:34
In less time it took you to write up your reply I added the first code, tested and it worked! Why I didn't put in the multiple quotes (duh!!).

I've never heard of the search and replace - but I'll check to see if that's avail for IVc4 (hope so!). Been looking through all the HELP to find SOMETHING besides rebuilding the string with code (too much typing!)

Thanks again!

Denise