Main Board > Tips and Techniques

How to find the number of fields in a string

(1/1)

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.

Navigation

[0] Message Index

Go to full version