- AuthorPosts
- May 8, 2014 at 4:06 pm #18376DavidParticipant
Hello. I create a macro to replace some strings in texts. What I need is to delete the empty lines in the file at the last step. I try to use “document.selection.Replace”, but it looks it doesn’t work.
Would you please share me an idea? Thanks!May 8, 2014 at 5:34 pm #18377FuzzyBearParticipantIf your empty line contains just a newline try this:
document.selection.Replace(“^$\n”, “”, eeReplaceAll | eeFindReplaceRegExp)If your empty line contains spaces and tabs try this:
document.selection.Replace(“^[[:blank:]]{1,}$\n”, “”, eeReplaceAll | eeFindReplaceRegExp)May 8, 2014 at 8:39 pm #18378DavidParticipantThank you,FuzzyBear!
It works very well on those empty lines in the file, but It looks it doesn’t work for last empty line. See the screenshot!http://ys-i.ys168.com/2.0/198138975/jifrflp2G6K3T548LTL/Screenshots-20.png
What I want is like this:
http://ys-i.ys168.com/2.0/198138976/j3K5I2V464MXLjifrfl/Screenshots-21.pngMay 8, 2014 at 8:46 pm #18383DavidParticipantSorry, please copy the link to your address bar of IE explorer and then open it. Click directly will get en error!
May 8, 2014 at 10:57 pm #18384StefanParticipantThat is because we are trying to match
“Start-of-line, none-or-more whitespace, Linebreak”
“^\\s*\\n”
But the very last line didn’t have a linebreak at all.
Better is to match
“Linebreak, none-or-more whitespace, End-of-line”
“\\n\\s*$”document.selection.Replace(“\\n\\s*$”,””,eeFindNext | eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
– – –
Or, for really empty lines only (don’t remove those with whitespace)
“Linebreak, End-of-line”
“\\n$”document.selection.Replace(“\\n$”,””,eeFindNext | eeReplaceAll | eeReplaceSelOnly | eeFindReplaceRegExp);
May 9, 2014 at 1:02 am #18385DavidParticipantNow it works ver well!
document.selection.Replace("\\n$","",eeFindNext | eeFindReplaceRegExp | eeReplaceAll);
Thanks again!
- AuthorPosts
- You must be logged in to reply to this topic.