Help rewriting numbers

I apologize if I post this incorrectly or in the wrong topic, I'm new to the forum..

I'm trying to rewrite a string but I don't know the best path of it. Basically I'm inputting a string from a Linux server telling me the VNC port of a VM, but it outputs it like this ":2" where 2 would be the end of 5902. (5900 is the standard VNC port). I created a change node that finds the colon and replaces it with 590 to create the full port number, and it works great for single digit port numbers.

The problem is that I have virtual machines that have ports that are multi-digit. For example, if a VM's port number is 5912, the server will output :12. When the change node sees the colon, it still replaces with 590, outputting 59012 which would be incorrect.

There wouldn't be anything above 99, so I'm basically trying to rewrite outputs ":0" to ":99" and format that correctly under the 5900 port number. (Hopefully that makes sense)

Any idea how to correctly rewrite the colon with the full port number?

Instead of replacing the colon with a number replace it with an empty string ("") then wrap that in a call to parseInt then add 5,900.

msg.payload = parseInt(xxx.replace(':', ''))  + 5900
return msg

That worked, thanks for the quick reply and the great solution!

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