How to replace beginning and ending quotes in a string

780 views
Skip to first unread message

Joe Morris

unread,
Jun 14, 2017, 2:46:09 PM6/14/17
to Node-RED
I have searched and searched and tried many different recommendations but I am unable to get rid of the surrounding quotes of a string.

I have this string as an input - "My Artist is "David Bowie"". What I need is - My Artist is "David Bowie"

I am sending the string into a function node where I am trying to get rid of the surround quotes. I am then sending the output of the function node to the debug node so I can see the payload resulting from the function node.

I have tried so many things and nothing works. Here are some of them:

---------------------------

function stripquotes(a) {
    if (a.charAt(0) === '"' && a.charAt(a.length-1) === '"') {
        return a.substr(1, a.length-2);
    }
    return a;
}
------------------------------
msg.payload = msg.payload.replace(/^"|"$/g, '') ;

-----------------------------
msg.payload.substring(1, msg.payload.length-1);
------------------------------

and many others. It almost seems as if the quotes are being added on AFTER the function.

Thanks

Joe

Nick O'Leary

unread,
Jun 14, 2017, 2:52:05 PM6/14/17
to Node-RED

The quotes around the content in the debug panel are there to make it clear it's a string; they are not part of the actual content.


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/606dd851-fbf5-4246-93bf-dc7d068d2c76%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Morris

unread,
Jun 20, 2017, 8:49:52 PM6/20/17
to node...@googlegroups.com

Thanks Nick,

 

I spent a day trying different things. I only get a ‘?’ form the system that I am dealing with so I assumed it was the quotes.

 

Once I ignored that I then was able to find the real error.

 

Joe

You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/5con1QFYzDw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.


To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Reply all
Reply to author
Forward
0 new messages