# Help rewriting numbers

**URL:** <https://discourse.nodered.org/t/help-rewriting-numbers/69445>\
**Category:** General\
**Created:** [23 October 2022 01:22 UTC](https://discourse.nodered.org/t/help-rewriting-numbers/69445 "2022-10-23T01:22:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![coleg06](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/coleg06/32/69589_2.png) [@coleg06](https://discourse.nodered.org/u/coleg06)\
**Post date:** [23 October 2022 01:22 UTC](https://discourse.nodered.org/t/help-rewriting-numbers/69445/1 "2022-10-23T01:22:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 October 2022 01:27 UTC](https://discourse.nodered.org/t/help-rewriting-numbers/69445/2 "2022-10-23T01:27:11Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![coleg06](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/coleg06/32/69589_2.png) [@coleg06](https://discourse.nodered.org/u/coleg06)\
**Post date:** [23 October 2022 01:37 UTC](https://discourse.nodered.org/t/help-rewriting-numbers/69445/3 "2022-10-23T01:37:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 November 2022 01:38 UTC](https://discourse.nodered.org/t/help-rewriting-numbers/69445/4 "2022-11-06T01:38:56Z")

</div>

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