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

18 Mar, 2025 05:24 AM
14 Mar, 2025 08:32 AM
10 Mar, 2025 06:36 PM
10 Mar, 2025 06:36 PM
10 Mar, 2025 06:36 PM

 

10 Mar, 2025 12:30 AM
02 Mar, 2025 12:34 AM
01 Mar, 2025 12:27 AM
24 Feb, 2025 11:24 PM
24 Feb, 2025 08:19 AM
24 Feb, 2025 01:07 AM