String Formatting
1374
Views
13
Comments
New
Builtin & User functions

Add support for string formatting in Expressions like python code.


In Outsystems we have something like this:

"My name is " + Name +" and I'm from  "+City


My ideia is to implemenmt something like this:

"My name is %s and I'm from %s " % (Name, City)

It could be amazing the use of patterns like string interpolation as .NET and other languages 

$"My name is {Name} and I'm from {City}"  Much cleaner and without counting number of tokens in big string formattings.

or C# pattern for string.format("My name is {0} and I'm from {1} ", Name, City)

Cheers,

Agree with Marcio. I'd work great in current web javascript editor. Having all that concatenations is really annoying.  I prefer $"My name is {Name} and I'm from {City}"

2014-02-07 17-02-43
Vasco Pessanha
Changed the category to
Builtin & User functions
2016-04-21 18-13-58
Nuno Rolo
 
MVP

I don't agree with this, the idea is a low-code platform. 

Creating a new formatting function instead of simply write the sentence in the way you need, doesn't help in anything, don't see any advantage.

Totally disagree with you Nuno. It happens very often you need to display text with variables, and using concatenation has a number of drawbacks, especially when using translations. I'm very often doing something like:

Replace("I have {0} bottles of beer on the wall", "{0}", IntegerToText(BottleCount))

in order to prevent concatenation in my code (and yeah, I should make that into a Function...).

2016-04-21 18-13-58
Nuno Rolo
 
MVP

Until now I didn't notice the need for having that kind of function, but I'm not against the creation of that function.

It was more a kind of warning to avoid that we lose the low-code concept.

But thanks for the heads up Kilian.

I think Roman's idea is better than the suggested one.

+1 for Roman's Idea

Was searching for this. +1

Something like .Net's like Márcio mentioned or even ES interpolation style -  `My name is ${Name} and I'm from ${City} ` would be great. It feels less like code.

@Nuno Damaso: the downside being you'd have variable names in the string literal, which would be difficult with translations.

Seems to make perfect sense, for me, especially in the case of C#.

Merged this idea with 'String Interpolation in Expressions' (created on 18 May 2020 20:08:29 by Grayson Udstrand)

Instead of needing to build strings using a clunky factory action or by doing something like this:

"This string is " + String.Length + " long."

we should be able to use something like string interpolation in C#. We would then basically be able to do the above like this:

$"This string is {String.Length} long."

Or, you know, something like that which maintains the OutSystems "low-code" flavor.  It would offer a more straightforward, less verbose means of putting dynamic strings in expressions. Here is how C# does it:

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated



This comment was:
- originally posted on idea 'String Interpolation in Expressions' (created on 18 May 2020 by Grayson Udstrand)
- merged to idea 'String Formatting' on 06 May 2021 05:41:37 by Daniël Kuhlmann