This function allows you to organize the iteration by all characters contained in the specified string so as to execute a certain operation for each character.
The function iterates by all characters (starting from the first one)
and on each step assigns the current character to a special external variable,
whose reference is passed in the stepVar
parameter
(using special '@'
operator).
That variable is also accessible within the subquery specified
in stepQuery
parameter.
The function executes that subquery for each character,
so the specified operation is processed for that character.
Basically, the function works as the following loop:
(However, at the moment, theindex = 0; while (index < str.length()) { step_var = str.charAt(index); // step subquery operators // ... index = index + 1; }
while
operator is not
supported in FlexQuery expressions, hence the need of this function.)
Parameters:
str
The string whose characters are to be iterated.
stepVar
The reference to the variable to which the current character is assigned to pass it to the subquery on each iteration step.The variable reference must be produced using
'@'
operator (see example below).
stepQuery
Specifies the subquery to be executed for each character.The subquery should be prepared using
FlexQuery()
function (see example below).Note: In addition to doing a certain operation with the current iterated character, the subquery may also signal whether the further iterations should be stopped. When the result returned by the subquery has a boolean type, the
true
value will indicate that the iterations should be continued, whereas thefalse
value will stop any further iterations.
Returns:
The number of iterations that has been made.
See Also:
FlexQuery()
Example:
The following expression will count the number of uppercase
Latin letters contained in the string passed in the 'text'
variable and print the result to the system console:
count = 0; iterateChars ( text, @c, FlexQuery ({ (c >= 'A' && c <= 'Z') ? count = count + 1; c != '.' }) ); echo (count)