|
Post by Walt Decker on Mar 13, 2023 9:17:54 GMT -5
DATA "1 2 3 4 5" DATA "1,2,3,4,5" DATA "1,2,,3,,4,5" DATA "1\ 2\ \ 3\ \ 4\ 5"
|
|
|
Post by Walt Decker on Mar 15, 2023 15:56:32 GMT -5
Guess no one wants to tackle this.
A$ = "1 2 3 4 5" PRINT "FIRST DATA "; A$ FOR I = 1 TO 5 PRINT WORD$(A$, I) NEXT I
A$ = "1,2,3,4,5" PRINT "SECOND DATA "; A$ FOR I = 1 TO 5 PRINT WORD$(A$, I, ",") NEXT I
A$ = "1,2,,3,,4,5" PRINT "THIRD DATA "; A$ FOR I = 1 TO 7 PRINT WORD$(A$, I, ",") '<--- PROBLEM HERE NEXT I
A$ = "1\2\\3\ \ 4\5" PRINT "FOURTH DATA "; A$ FOR I = 1 TO 7 PRINT WORD$(A$, I, "\") '<--- PROBLEM HERE NEXT I
END
I know what the problem is. Anyone want to hazard a thought?
|
|
cundo
Full Member
Muchas Gracias!!
Posts: 146
|
Post by cundo on Mar 15, 2023 16:16:51 GMT -5
It reads whatever character is next to the delimiter. the problem is, with each delimiter, it expects string data afterwards .
|
|
|
Post by tenochtitlanuk on Mar 15, 2023 17:28:05 GMT -5
See Wikipedia-
The CSV file format is not fully standardized. Separating fields with commas is the foundation, but commas in the data or embedded line breaks have to be handled specially. Some implementations disallow such content while others surround the field with quotation marks, which yet again creates the need for escaping if quotation marks are present in the data. This will apply too to space-separators, reverse-slash separators, or w.h.y. It is therefore up to the CODER to ensure that the data fields do not include the separator character- if you ignore that caution, beware!
As a heavy user of word$( I have never had cause to see the anomalous outputs!
|
|
|
Post by Walt Decker on Mar 16, 2023 10:28:38 GMT -5
That is correct. The delimiter defines fields in a string. If there is one delimiter there are two fields, two delimiters produce three fields, etc., even if the field delimeters are adjacent producing an empty field. The user supplied delimeter should over-ride the default white-space delimiter; it does not. The coder should be aware of this quirk and supply at least a white-space if a field might be empty.
I use my own parsing routines to avoid this.
|
|
|
Post by tsh73 on Mar 16, 2023 13:01:58 GMT -5
I second that.
That's in the docs, so yes, should be aware. It is known from the help file on Word$ that double delimiter (empty word) return delimiter.
You added a space between\\; well that could be taken care of as well.
1 2 3 4 5 delim is > < 1 1 2 2 3 3 4 4 5 5 1,2,3,4,5 delim is >,< 1 1 2 2 3 3 4 4 5 5 1,2,,3,,4,5 delim is >,< 1 1 2 2 3 3 4 4 5 5 1\ 2\ \ 3\ \ 4\ 5 delim is >\< 1 1 2 2 3 3 4 4 5 5
DATA "1 2 3 4 5" DATA "1,2,3,4,5" DATA "1,2,,3,,4,5" DATA "1\ 2\ \ 3\ \ 4\ 5"
for i = 1 to 4 read a$ print a$ delim$=getDelim$(a$, "0123456789") print "delim is >"; delim$;"<"
j = 0 'real word position k = 0 'non-empty word position while(1) j=j+1 w$=word$(a$,j,delim$) if w$="" then exit while 'end if trim$(w$)="" or w$=delim$ then 'skip empty word else k=k+1 print ,k, w$ end if wend next
function getDelim$(a$, validChars$) getDelim$="" for i = 1 to len(a$) c$=mid$(a$,i,1) if not(instr(validChars$, c$)) then getDelim$=c$: exit function next end function
|
|
|
Post by marshawn on Mar 17, 2023 11:12:41 GMT -5
|
|
|
Post by tsh73 on Mar 17, 2023 12:19:33 GMT -5
I was so impressed by WORD$ commend that I recreated it in some other language (was it VB?) But I think I used it only once because mostly I write LB (JB) programs.
|
|