Forum Discussion

ShaneMiller1's avatar
ShaneMiller1
Qrew Cadet
2 years ago

Formula to remove blank lines from text

Hello, I have a field that is being generated by a pipeline and unfortunately due to the formatting of my jinja, creates blank lines:

Is there a way to format this via a formula text field so that it appears as follows:


or perhaps edit the jinja2 so that it doesn't create the spaces. I am open to all recommendations

Thank you
------------------------------
Shane Miller
------------------------------

  • Will the result always be in that exact format? ie, only 2 lines both starting with underscore?

    _text

    _moretext



    ------------------------------
    Mike Tamoush
    ------------------------------
    • ShaneMiller1's avatar
      ShaneMiller1
      Qrew Cadet

      Hey Mike,

      That's correct. I intentionally threw that in the Jinja2 so that I could hopefully format it using another formula text field.
      I have gotten close:


      Formula field is as follows:
      SearchAndReplace([testing jinja2 pipelines], "\n", "")



      ------------------------------
      Shane Miller
      ------------------------------
    • ShaneMiller1's avatar
      ShaneMiller1
      Qrew Cadet

      Sorry, to elaborate, it could be more than two items with a _beforethetext.
      My jinja2 code tests 15 or so fields to see if the previous value is different than the current value. The blank spaces I am experiencing can be anywhere, and there can be any number of _textlikethis up to 15 I suppose



      ------------------------------
      Shane Miller
      ------------------------------

  • I'm sure editing the Jinja is probably best practice, so if someone knows Jinja, that is the way to go. I am not very good at Jinja, so try this in your formula field:

    var text LinesRemoved = SearchAndReplace([testing jinja2 pipelines], "\n", "");

    Trim(SearchandReplace($LinesRemoved, "_", "\n"))

    //This is untested and I am not sure if Trim will remove the first blank line that will be put back in replacing the first underscore. If it doesn't work, let me know I have other ideas.



    ------------------------------
    Mike Tamoush
    ------------------------------
    • ShaneMiller1's avatar
      ShaneMiller1
      Qrew Cadet

      I agree with you about reformmating my jinja2. I'll leave it below my response to you in case anyone wants to take a stab at fixing it.
      Unfortunately, that formula doesn't work. I can't pin-point why it doesn't, I feel like it should.
      This was the outcome it gave me:



      ------------------------------
      Shane Miller
      ------------------------------
      • ShaneMiller1's avatar
        ShaneMiller1
        Qrew Cadet

        Here is my Pipeline and also the Jinja2 that follows:



        ------------------------------
        Shane Miller
        ------------------------------