|
Post by kokenge on Jan 9, 2009 9:38:16 GMT -5
When there is not data passed between a separator, word$ returns the separator. a$ = "1|2|3|4||6|" for i = 1 to 6 a1$ = word$(a$,i,"|") print i;" ";a1$ next i wait
Check the 5th item..
|
|
|
Post by Janet on Jan 9, 2009 11:02:51 GMT -5
Liberty BASIC behaves the same way. I wonder if that's the way all BASIC's handle Word$()? The workaround is to add an if statement if a1$ = "|" then a1$ = "" but I'd bet the farm Dan already knows that.
|
|
|
Post by StefanPendl on Jan 9, 2009 15:44:28 GMT -5
Liberty BASIC behaves the same way. I wonder if that's the way all BASIC's handle Word$()? The workaround is to add an if statement if a1$ = "|" then a1$ = "" but I'd bet the farm Dan already knows that. I do not think all splitting functions of all BASIC dialects work this way, but it is the only thing that enables one to continue parsing a delimited string with empty fields in between. Seems more like a feature, but the help should mention this.
|
|
|
Post by kokenge on Jan 9, 2009 18:54:00 GMT -5
Actually what I do is use a blank and the separator when making the string, and then only use the separator and a trim$ when parsing it apart. In the example, the 5th entry is now blank. Just another way around the problem, and saves a IF command. a$ = "1 |2 |3 |4 | |6 |" for i = 1 to 6 a1$ = trim$(word$(a$,i,"|")) print i;" ";a1$ next i wait
|
|
|
Post by Carl Gundel - admin on Jan 16, 2009 22:11:39 GMT -5
It's supposed to work this way. The delimiter chosen should be one that you know won't be in the data string. Some people use TAB (ASCII 9) for example. When the delimiter is returned you know you have a blank entry. When an empty string is returned you have gone past the end.
I should ammend the help file to explain this.
-Carl
|
|