Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #18376
    David
    Participant

    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!

    #18377
    FuzzyBear
    Participant

    If 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)

    #18378
    David
    Participant

    Thank 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.png

    #18383
    David
    Participant

    Sorry, please copy the link to your address bar of IE explorer and then open it. Click directly will get en error!

    #18384
    Stefan
    Participant

    That 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);

     
     

    #18385
    David
    Participant

    Now it works ver well!
    document.selection.Replace("\\n$","",eeFindNext | eeFindReplaceRegExp | eeReplaceAll);

    Thanks again!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.