How can I strip carriage returns from a string?
Is there any way within NodeBox to strip carriage returns and line feeds out of a sting?
I tried feeding \r and \n into a replace node but that didn't work. I suppose I could make a custom node to do this, but it would be nice not to have to do this. I wish the trim node could also trim carriage returns, line feeds, and tabs.
John
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by john on 05 Feb, 2017 04:59 AM
Since I hate having to make custom nodes that I then have to keep track of, I decided to see if I could find some way of doing this entirely within NodeBox. It wasn't easy but I finally came up a way (attached). It's complicated, but it works.
The As_NumberList node converts the string into ASCII values. I then test for linefeeds (ASCII 10), convert the string to characters and use a Cull and a First to isolate a single LineFeed character (10). Once I have that I can feed it into a Replace node. If there are no linefeeds I just pass through the original string using a switch.
This exercise would not have been necessary if there was some way of entering a line feed directly into the OLD field of a Replace node. (Is there?). One alternative would be to provide a CHAR node that converts an ASCII code back into a character. It's weird that you can convert a char into ASCII but not the other way around.
This subnetwork could be easily modified to deal with other invisible characters.
Enjoy!
John
Support Staff 2 Posted by john on 05 Feb, 2017 05:14 AM
Oops. The stripLF subnetwork I just uploaded didn't have the final node rendered, so wouldn't work.
Here is the corrected version. (Wish I could just delete previous comment, but I can't.)
Sorry. Enjoy!
John