PlanetSquires Forums

Support Forums => José Roca Software => Topic started by: Paul Squires on July 28, 2026, 05:46:33 PM

Title: AfxStrParseCountAny bug
Post by: Paul Squires on July 28, 2026, 05:46:33 PM
Hi José,

Looks like AfxStrParseCountAny() has a little bug in it.

' ========================================================================================
' * Return the count of delimited fields from a string expression.
' If wszMainStr is empty (a null string) or contains no delimiter character(s), the string
' is considered to contain exactly one sub-field. In this case, AfxStrParseCountAny returns the value 1.
' Delimiter contains a set of characters (one or more), any of which may act as a delimiter character.
' Delimiters are case-sensitive.
' Example: DIM nCount AS LONG = AfxStrParseCountAny("1;2,3", ",;")
' ========================================================================================
PRIVATE FUNCTION AfxStrParseCountAny (BYREF wszMainStr AS CONST WSTRING, BYREF wszDelimiter AS CONST WSTRING = ",") AS LONG
   DIM nCount AS LONG = 1
   DIM nPos AS LONG = 1
   DO
      nPos = INSTR(nPos, wszMainStr, ANY wszDelimiter)
      IF nPos = 0 THEN EXIT DO
      nCount += 1
      nPos += LEN(wszDelimiter)   '<---- THIS IS THE PROBLEM
      ' nPos += 1   '<---- THIS IS THE FIX
   LOOP
   RETURN nCount
END FUNCTION
' ========================================================================================
Title: Re: AfxStrParseCountAny bug
Post by: José Roca on July 28, 2026, 08:42:22 PM
You're right. I have modified it.