Can AI be the answer ?
-
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 .
Props for mentioning regex. Most devs never take the time to learn it, but it's an extremely useful tool.
Jeremy Falcon
-
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
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
-
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
-
You seem like the sort who would use a Nutrimatic machine to simply boil dried leaves. :wtf:
-
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
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
-
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
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
-
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
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
-
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
(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
-
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
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
-
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
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
-
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
Props for trying, but I found out he ain't open to suggestion.
Jeremy Falcon