Searching character's

i want to check if have some words in a phrase, like "Bom". Think that is how to start but dont know how to check if "Bom" exist in my phrase.Captura%20de%20tela%20de%202018-08-16%2015-02-03

Try the switch node "Contains" option.

I need to check if my msg.payload out have the work "bom". I put the switch node and dont have success

This should help you

[{"id":"c4dc9486.8bb738","type":"inject","z":"dc97015.997e9","name":"","topic":"","payload":"this is a string with bom in it","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":610,"y":80,"wires":[["19c6b999.e75d56"]]},{"id":"19c6b999.e75d56","type":"switch","z":"dc97015.997e9","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"bom","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":770,"y":80,"wires":[["8b5d4786.14d8a8"]]},{"id":"8b5d4786.14d8a8","type":"debug","z":"dc97015.997e9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1210,"y":80,"wires":[]}]

The contains option is case sensitive. You need to use every combination you can figure out if you need to find them from arbitrary text.
Bom, BOM, and is the "!BOM!" as dangerous as the "bOm" :slight_smile:

or copy msg.payload to msg.lowercase and force the contents of that to lowercase and then run the search on that

And then it's time for regex :laughing:

1 Like

I used the code below to set wath i was looking for. Thanks U guys.
var msgList = [];

var letterList = msg.payload.output.text[0];

letterList = letterList.toString('uft8');

var tam_msg = letterList.length;

for (var i = 0; i < tam_msg; i++){

if(letterList[i] == 'b' && letterList[i+1] == 'o' && letterList[i+2] == 'm'){

//code_below

}

}

return [msgList];

It's probably worth looking at the JavaScript .indexOf function.

JavaScript has lots of ways to check if a string appears within another string without you having to loop over the individual characters.

if (/bom/.test(msg.payload.output.text[0])) {

}
if (msg.payload.output.text[0].indexOf("bom") > -1) {

}
1 Like

Seems a lot easier to use a switch node with a regex:

image

6 Likes

Try to avoid using the function for things that can be solved with the "Switch" or the "Change", soon you will realize how powerful are those 2 nodes.
#fikdica