1
 Follower
16
 Likes

Text Extension : String.Format

System Components
On our radar
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.
Created on 21 Aug 2014
Comments (5)
+1
From the multilingual and message diversion perspective, I think this idea is very useful.
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.

J.Ja

Hi,
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....

Regards
Tomasz
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...

SyntaxEditor Code Snippet

SyntaxEditor Code Snippet

Replace("Demo for Replacing text with index parameter with From and To Date From {0} ","{0}",FormatDateTime(#2018-05-08#,"dd-MM-yyyy"))+Replace("To {1} ","{1}",FormatDateTime(#2018-05-09#,"dd-MM-yyyy"))

And its Works Fine for me.. 

views
324
Followers
1