Help with string manipulation

I am sending some data to a display with 2 lines of 16 char's.
The top line I want to display the amount of Watts taken from the net and the second line the returned to the net. So I want the first string to be exactly 16 chars. I came up with this but that doesn't work in a function node:

var meterreceived = global.get('meter_received');
var regel1 = "Watt in : " + global.get('meter_cons');
var lregel1 = regel1.lenght;
for (var i = lregel1; i < 16; i++) regel1 = regel1 + " ";
msg.payload =  regel1 + "terug: " + meterreceived;

No spaces are inserted when the line is less than 16 chars.
meter_cons is something between 0 and 40000.
I think I have the for wrong but I cannot find someting else.

I think you could try padStart(maxLength, fillString). So something like

let text = "Watt in : ";
let regel1 = text + global.get('meter_received').padStart(16 - text.length,' ');

You have a typo there.

oops... i didn't see that.. the problem of being a Dutchman.... now it turns orange...

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.