Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Can AI be the answer ?

Can AI be the answer ?

Scheduled Pinned Locked Moved The Lounge
questiondiscussion
21 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B BernardIE5317

    a trivial AWK program would do the trick . or you can utilize regular expressions Find/Replace though i am still uncertain how to handle end of line and new line but am certain it can be done as i have been successful in past though i do not recall the details . a little learning experimentation will no doubt do the trick .

    J Offline
    J Offline
    Jeremy Falcon
    wrote on last edited by
    #11

    Props for mentioning regex. Most devs never take the time to learn it, but it's an extremely useful tool.

    Jeremy Falcon

    1 Reply Last reply
    0
    • L Lost User

      text = text.Trim().Replace( "\n\n", "\n" );

      "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

      J Offline
      J Offline
      Jeremy Falcon
      wrote on last edited by
      #12

      You'd want something more like this: /^\s*?(?:\r\n|\r|\n)\s*?$/gm. Notice the global modifier, it will help with the newline side of things for the second line.

      Jeremy Falcon

      L 1 Reply Last reply
      0
      • L Lost User

        I have been unsuccessfully asking for an editor to remove empty lines... As is customary , received plenty of opinions why NOT to do it... Would that be perfect application for AI ? if (there is nothing ) remove nothing

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #13

        Certainly better to use AI for that rather than rely on something that actually mattered.

        P 1 Reply Last reply
        0
        • J jschell

          Certainly better to use AI for that rather than rely on something that actually mattered.

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #14

          You seem like the sort who would use a Nutrimatic machine to simply boil dried leaves. :wtf:

          1 Reply Last reply
          0
          • D Dan Neely

            That only works with completely empty lines. For a production system, you'd want a regex that matches 0 or more space/tab characters between the newlines.

            Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #15

            text = text.Trim().Replace( "\n\n", "\n" ).Replace("\t", "").Replace(" ", ""); Anything else?

            "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

            D 1 Reply Last reply
            0
            • R Ravi Bhavnani

              I think you meant this. :)

              while (text.Contains("\\n\\n")) {
                  text = text.Replace("\\n\\n", "\\n");
              }
              

              /ravi

              My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #16

              You've obviously not tested my answer.

              "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

              1 Reply Last reply
              0
              • J Jeremy Falcon

                You'd want something more like this: /^\s*?(?:\r\n|\r|\n)\s*?$/gm. Notice the global modifier, it will help with the newline side of things for the second line.

                Jeremy Falcon

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #17

                Mine works ... and I can read it.

                "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                J 1 Reply Last reply
                0
                • R Ravi Bhavnani

                  I think you meant this. :)

                  while (text.Contains("\\n\\n")) {
                      text = text.Replace("\\n\\n", "\\n");
                  }
                  

                  /ravi

                  My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #18

                  (I think I failed to copy my own code)

                  "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                  1 Reply Last reply
                  0
                  • L Lost User

                    text = text.Trim().Replace( "\n\n", "\n" ).Replace("\t", "").Replace(" ", ""); Anything else?

                    "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                    D Offline
                    D Offline
                    Dan Neely
                    wrote on last edited by
                    #19

                    That doesn't do what you think it does.

                    Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius

                    J 1 Reply Last reply
                    0
                    • L Lost User

                      Mine works ... and I can read it.

                      "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                      J Offline
                      J Offline
                      Jeremy Falcon
                      wrote on last edited by
                      #20

                      Yours works only in a very specific circumstance for something you find useful. Yours will leave any extra whitespace and make no distinction between a blank line or line with whitespace. This also means yours cannot be automated. So, you're welcome.

                      Jeremy Falcon

                      1 Reply Last reply
                      0
                      • D Dan Neely

                        That doesn't do what you think it does.

                        Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius

                        J Offline
                        J Offline
                        Jeremy Falcon
                        wrote on last edited by
                        #21

                        Props for trying, but I found out he ain't open to suggestion.

                        Jeremy Falcon

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups