Leftpad doesn't work when concatenating with "+" (and number-like strings are converted to numbers)

When you concatenate a string using + instead of concatenate(), LeftPadding is ignored:

In fact, this led me to realize that all number-like strings are first forced to numbers before being converted back into strings for concatenation.

"Hello" + 007
= “Hello7” (fair enough)

"Hello" + "007"
= “Hello7” (unexpected)

Perhaps this is the intended behaviour, but I certainly find it weird :slight_smile:

You’re not the first one mentioning this (or alike) in those past few days :blush:

I have no idea if it’s intended or not though :woman_shrugging:

But I like this point of view concerning this trouble :

1 Like

Hi @Nick_HE,
I think that the “+” operator works in string concatenation just as a side effect.
This is the reason why Concatenate() and Format() are provided, I guess.

I would not recommend to use it for safe string concatenation, unless a fully overloaded behaviour (i.e. an explicit type interpolation is implemented in the string context) will be provided (if ever).



I don’t think + was intended for use in “concatenate” cases at all. As someone already mentioned I think it main purpose is to be used in math operations and as @Federico_Stefanato mentioned Concatenate() and Format() functions are there to cover “text formatting” use cases.

1 Like