Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:16 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Possible Bug in FIELD$ function in MMBasic 5.05.03

Author Message
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 405
Posted: 04:31pm 19 Aug 2020
Copy link to clipboard 
Print this post

The manual says that the string2 argument to FIELD$ can hold more than one delimiter. I interpret this to mean 'you can use any character in this string as a delimiter." (This is the usual way such a parser works in other language runtime libraries.)

However, this does not work as I expect:

rstr$ = "100, 100, 100"
dstr$ = " ,"

c1$ = FIELD$(rstr$, 1, dstr$)
c2$ = FIELD$(rstr$, 2, dstr$)
c3$ = FIELD$(rstr$, 3, dstr$)

If the delimiters in rstr$ are just spaces, then FIELD$ returns the correct fields for all 3 items. But if rstr$ has commas or any combination of spaces and commas, then only the first item is correct and the other two are null strings.

Does anyone see the same thing? Is my interpretation of the desired behavior wrong?
Thanks!
 
darthvader
Regular Member

Joined: 31/01/2020
Location: France
Posts: 87
Posted: 04:54pm 19 Aug 2020
Copy link to clipboard 
Print this post

Hi ,

i just tested with v5.05.05b11 and it seem to work :)
Theory is when we know everything but nothing work ...
Practice is when everything work but no one know why ;)
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 10:04pm 19 Aug 2020
Copy link to clipboard 
Print this post

Works OK for me in V5.05.x but there is a mistake in the manual, not relevant to you problem.

I tried all combinations of space and comma and it works as per the manual.

The mistake is in the example:
  Quote  s$ = "foo, 'boo, zoo', doo"
r$ = FIELD$(s$, 3, ",", "'")
will result in r$ = "boo, zoo".


should be
  Quote  s$ = "foo, 'boo, zoo', doo"
r$ = FIELD$(s$, 2, ",", "'")
will result in r$ = "boo, zoo".


Jim
VK7JH
MMedit
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025