How to find the number of fields in a string

Started by PxPlus, May 30, 2018, 04:34:27 PM

Previous topic - Next topic

PxPlus

If you have a string with a series of delimited fields such as:
  "a,b,c,d,e,f,"

You can figure out the number of fields in the string by using the POS function to count the number of delimiters.

  Count = POS("," = <string>,1,0)

Giving the POS function a increment of 1 with an occurence number of zero causes it to return the count instead of the position.

The only thing to watch for is if the string does not have a trailing delimiter such as "a,b,c" -- in this case the number will be one too low.