Text Extension : String.Format

By Célia Corte on 21 Aug 2014
Change Text Extension to add a funtion equivalent to string.Format in Net and Java
Example: string output = String.Format("At {0} in {1}, the temperature was {2} degrees.", dat, city, temp);
I would like to create a site property with this conditions.
K N21 Aug 2014
From the multilingual and message diversion perspective, I think this idea is very useful.
Justin James22 Aug 2014
The one problem is that OutSystems does not handle variable-length parameters well. Even if you used a record list, I think it would need to be restricted to a certain number of parameters.

Do you think 10 replacement string parameters would be sufficient? I can build this into an Extension pretty easily.


I would even agree to supply just two parameters: the pattern and the list of texts. This is not only the case when the order of placeholders depends on the language. The example with temperature should be implemented now as something like this:

"At " + dat + " in " + city + ", the temperature was " + temp + " degrees.".

This means that we have to translate four texts:
  • "At "
  • " in "
  • ", the temperature was "
  • " degrees."
It's horrible....

J.26 Jun 2015
The idea is very much loved :)

However, you still can do it yourself.

the string will be the same as with {0} etc, assuming there will be a maximum of say 5 parameters.
just create an function to replace {0} with first parameter.

Replace(Replace(Text, "{0}", InputParameter1), "{1}, InputParameter2)
or even a regex_replace etc.

not very friendly, but it gets the job done and you ende up with only 1 string to translate...