How can I strip carriage returns from a string?

john's Avatar

john

02 Feb, 2017 01:59 AM

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

  1. Support Staff 1 Posted by john on 05 Feb, 2017 04:59 AM

    john's Avatar

    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

  2. Support Staff 2 Posted by john on 05 Feb, 2017 05:14 AM

    john's Avatar

    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

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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

Recent Discussions

16 Feb, 2025 11:13 AM
15 Feb, 2025 12:51 PM
06 Feb, 2025 01:37 AM
04 Feb, 2025 06:32 AM
04 Feb, 2025 05:04 AM

 

30 Jan, 2025 09:31 AM
30 Jan, 2025 09:08 AM
30 Jan, 2025 08:40 AM
24 Jan, 2025 07:50 AM
22 Jan, 2025 11:42 PM
21 Jan, 2025 09:43 AM