How can I strip carriage returns from a string?

john's Avatar

john

Feb 02, 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 Feb 05, 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 Feb 05, 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

        No formatting (switch to Markdown)

          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

            12 May 19:26
            09 May 13:15
            07 May 03:57
            06 May 06:46
            06 May 02:15

             

            21 Apr 10:47
            21 Apr 10:41
            21 Apr 05:56
            19 Apr 19:17
            18 Apr 00:04
            14 Apr 22:18