The SFMT Operator

by Support Team

Example of a did you know Genero post containing Genero code

The SFMT operator was introduced to Genero in 1.3.  It allows you to replace placeholders in strings with values.

Potential uses are as an alternative to , and || for string concatenation.  Which one of these three techniques is easiest to read …

DEFINE sql, select_clause, from_clause, where_clause, order_clause STRING

LET sql = "SELECT ", select_clause, " FROM ", from_clause, " WHERE ", where_clause, " ORDER BY ", order_clause

LET sql = "SELECT " || select_clause || " FROM " || from_clause || " WHERE " || where_clause || " ORDER BY " || order_clause

LET sql = SFMT("SELECT %1 FROM %2 WHERE %3 ORDER BY %4", select_clause, from_clause, where_clause, order_clause)

… and for localization where the order that the parameters get inserted into the string may vary based on the language grammar

DISPLAY SFMT(%"error.date.greater.than", %"from.date", %"to.date")

where

"error.date.greater.than" = "%1 must be greater than %2"

or

"error.date.greater.than" = "%2 must not be less than %1"

I quite often see source code using , and || to concatenate strings, when I believe it would be easier to read if SFMT was utilised.