¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: Parsing a string


 

¿ªÔÆÌåÓý

BTW, this can all be done in one function node using Mick¡¯s example then looking for each msg.out to either be 0 or 1 and setting msg.out to false or true. (if/else)

?

More than one way to get to the desired output.

?

Dave wo2x

?

From: [email protected] <[email protected]> On Behalf Of Mick - W8BE
Sent: Friday, January 29, 2021 3:01 PM
To: [email protected]
Subject: Re: [nodered-hamradio] Parsing a string

?

Here is a function to split the input and output a msg for each bit.? ?I used a string of 10000000 as the inject

?

?

The output gives you the msg.payload and msg.topic

?

Here is the function.

?

var output = msg.payload.split("");
msg.out0 = parseInt(output[0]);
msg.out1 = parseInt(output[1]);
msg.out2 = parseInt(output[2]);
msg.out3 = parseInt(output[3]);
msg.out4 = parseInt(output[4]);
msg.out5 = parseInt(output[5]);
msg.out6 = parseInt(output[6]);
msg.out7 = parseInt(output[6]);
msg.out8 = parseInt(output[7]);
msg.out9 = parseInt(output[8]);
msg1 = {topic: 'Bit 1',payload:msg.out0};
msg2 = {topic: 'Bit 2',payload:msg.out1};
msg3 = {topic: 'Bit 3',payload:msg.out2};
msg4 = {topic: 'Bit 4',payload:msg.out3};
msg5 = {topic: 'Bit 5',payload:msg.out4};
msg6 = {topic: 'Bit 6',payload:msg.out5};
msg7 = {topic: 'Bit 7',payload:msg.out6};
msg8 = {topci: 'Bit 8',payload:msg.out7};
msg9 = {topic: 'Bit 9',payload:msg.out8};

node.send(msg1);
node.send(msg2);
node.send(msg3);
node.send(msg4);
node.send(msg5);
node.send(msg6);
node.send(msg7);
node.send(msg8);
node.send(msg9);

return;

You could then run this into a switch node for further?processing or just modify it by creating a var instead of msg and then process it in the function.?

?

On Fri, Jan 29, 2021 at 1:53 PM David De Coons wo2x <RocketNJ@...> wrote:

Neal beat me to it.

?

Split/Switch is the way to go. Easy.

?

73

Dave wo2x

?

?

From: [email protected] <[email protected]> On Behalf Of Neal Pollack
Sent: Friday, January 29, 2021 1:38 PM
To: [email protected]
Subject: Re: [nodered-hamradio] Parsing a string

?

Another way to split the outputs;

?

?

On Fri, Jan 29, 2021 at 10:24 AM Michael Walker <va3mw@...> wrote:

I have a workable solution

?

(Dave, no driving and texting)? :)

?

Take the string and convert it to csv.? I can manage the rest.??

?

But, I will like to see your idea.

?

73

?

?

On Fri, Jan 29, 2021 at 1:17 PM David De Coons wo2x <RocketNJ@...> wrote:

I¡¯ve got a solution. I should be home in 1/2 hr.

?

Dave wo2x

?

?

Sent from my waxed string and tin cans.?

?

On Jan 29, 2021, at 1:11 PM, Michael Walker <va3mw@...> wrote:

?

Hi Neal

?

Yes, that is the status of 8 relays that I need to break out so I can build an LED panel (so to speak)

?

Mike?

?

On Fri, Jan 29, 2021 at 1:09 PM Neal Pollack <nealix@...> wrote:

Mike:

?

I don't have the actual answer, but I *think* I understand how to describe what you want:

?

Given a binary string of 1's and 0's such as, for example, 10010110 , parse out each digit position, and assign?each digit to
a separate boolean variable name set to 1 or 0.? ? Is that what?you're looking for?

?

Neal

?

On Fri, Jan 29, 2021 at 9:52 AM Michael Walker <va3mw@...> wrote:

Hi All

?

I have a string I need to parse of 8 binary values being returned from a relay board

?

10000000

?

What is the best way to parse out the status of each of these relays???

?

I looked at 'string' but I can't see a method that allows me to pull the boolean out 1 at a time.

?

thoughts?

?

Mike va3mw

?

Join [email protected] to automatically receive all group messages.