Convert decimal to char

Hi my friends,
In part of my flow, I faced an output in decimal format like this :

[{"id":"7c5d1a66.b99a74","type":"tab","label":"Flow 9","disabled":false,"info":""},{"id":"74bc4c7d.bac1e4","type":"debug","z":"7c5d1a66.b99a74","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":450,"y":80,"wires":[]},{"id":"4e14428e.9c0dac","type":"inject","z":"7c5d1a66.b99a74","name":"","topic":"","payload":"50, 54, 46, 48, 48,","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":120,"wires":[["74bc4c7d.bac1e4"]]}]

As you see below :
https://upload.wikimedia.org/wikipedia/commons/d/dd/ASCII-Table.svg
these are decimal code that will be "26.00" in char format
How can I convert any decimall input to char format ?
Thanks

For the sake of this example you want to convert msg.payload

Try String(msg.payload)

1 Like

I used a function node with this code, but noting changed !

msg.payload=String(msg.payload)
return msg;
msg.payload : string[19]
"50, 54, 46, 48, 48,"

Hi @tarahi

Given an input of the string "50, 54, 46, 48, 48,", you need to first convert that to an array of bytes.

The format isn't ideal as it isn't in a standard like JSON. If you are able to change whatever is producing that string, that would make your life easier.

But if we take the format you have shared as a given, then...

// Split the string into array of individual values
var parts = msg.payload.split(",");

// Remove the last blank part caused by the trailing comma
parts.pop();

// Parse each part of the string to a number
var bytes = parts.map(v => parseInt(v))

// Create a new Buffer from those bytes and convert back to String
msg.payload = Buffer.from(bytes).toString();

return msg;
1 Like

I see @knolleary is replying.

I think I shall let him answer the question better than I can.

But I think there is a problem with what you are typing.
String[19] (note the capitol S) will make 19 a string.
But I think there is a problem with the "50, 54, 46, 48, 48".... I think that is an array.

Exactly what I wanted ! :heart: :heart: :heart:
Thanks a lot ... :kissing_heart:

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