Feature request: Easier string concatenation and template literals in PLCnext /w ST
Hello PLCnext Community!
I'm reaching out to discuss and suggest an improvement for string handling in PLCnext. As many of you might agree, working with strings in Structured Text can sometimes feel like you're trying to solve a Rubik's Cube – it's doable, but a straightforward solution would be much appreciated!
Currently, when we want to create a string like "Hello PLCnext community, it's [dayCountDown] days till the new month starts", we have to jump through a few hoops. Here's what we do now:
1. Use `TO_STRING` to convert variables to strings (and hope it doesn't argue about the data types).
2. Use `CONCAT` to put together multiple strings, which can feel like trying to fit a square peg in a round hole if you've got more than two strings.
Here's an example of the current method:
fullString := CONCAT('Hello PLCnext community, it’s ', CONCAT(TO_STRING(dayCountDown, '{0}'), ' days till the new month starts'));
Wouldn't it be wonderful if we could simplify this process? My suggestion is to introduce direct string concatenation with the `+` operator or, even better, support for template literals similar to those in JavaScript with backticks and `${variable}`.
Imagine the simplicity and clarity we could achieve:
fullString := `Hello PLCnext community, it's ${dayCountDown} days till the new month starts`;
This change would not only save time and reduce code complexity but also bring a smile to our faces, much like when you find an extra cookie in your cookie jar!
What do you all think? I believe this could be a small change with a big impact on our day-to-day programming experience when using strings with variables in it.
Looking forward to hearing your thoughts and insights!
Best,
Michel
Comments
I am writing to follow up on an answer I received via email from Phoenix Contact regarding the use of backticks in the PLCnext Engineer interface, which was mentioned to have been shared on the forum as well. Regrettably, this explanation is not visible (anymore) in the forum discussions. For the sake of clarity and to aid others who might have the same thoughts, I was hoping to see this detailed response posted publicly. The content of the email was as follows:
"We have discussed this topic with our development and PM and have come to the following conclusion. We see the benefits of using backticks as in JavaScript. However, the ST language is defined by the international standard IEC 61131-3 and we have implemented our editor according to it.
Furthermore, the second CONCAT command in your example line is not necessary.
fullString := CONCAT('Hello PLCnext community, it’s ', TO_STRING(dayCountDown, '{0}'), ' days till the new month start');"
I would appreciate if this could be addressed, ensuring that the information is accessible to all users on the forum, which would greatly contribute to the collective knowledge base.
I looking through manual thousand times but never noticed this before.... It seems that this option have to be bolded and placed in the head of list)
There are a few functions that can have inputs added, e.g. the logic functions:
CONCAT is just another example of a function with this feature.
Note that it's possible to add inputs in both the ST and the FBD versions of these functions.
mind.blown.