Remove empty lines in text using Visual Studio

后端 未结 11 1350
借酒劲吻你
借酒劲吻你 2020-12-12 08:36

How to remove empty lines in Visual Studio?

相关标签:
11条回答
  • 2020-12-12 09:08

    Since Visual Studio 2012 changed its regex syntax, the original answers by Ala translate into the following in VS 2012:

    Remove single blank lines

    Old:

    ^:b*$\n
    

    New:

    ^(?([^\r\n])\s)*\r?$\r?\n
    

    Visual Studio 2013 (thanks to BozoJoe and Joe Johnston):

    ^\s*$\n
    

    Remove double blank lines

    Old:

    ^:b*\n:b*\n
    

    New:

    ^(?([^\r\n])\s)*\r?\n(?([^\r\n])\s)*\r?\n
    

    Rolls right off your tongue.

    Here is the conversion sheet from MSDN.

    0 讨论(0)
  • 2020-12-12 09:09

    Ctrl + K, Ctrl+D auto formats the current document and that removes unnecessary space in your code. It helps keep your code readable if that what you were looking for.

    0 讨论(0)
  • 2020-12-12 09:12

    In Visual Studio 2013 (Version 12.0.20623.01) i removed empty lines with this regular expression ^\r\n In the screen you can see the matched lines indicated by the brown squares.

    Visual Studio 2013 replace empty lines

    0 讨论(0)
  • 2020-12-12 09:15

    Tested in VS 2012 to allow for pure line feeds.

    ^\s*$\n 
    

    hth

    0 讨论(0)
  • 2020-12-12 09:17

    Using Visual Studio 2017 and above

    in Current Document

    use shortcut

    • Open Tools > Options or press Alt + T + O
    • Under Environment tab > Keyboard
    • Search for "DeleteBlank" and select Edit.DeleteBlankLines
    • Add a new shortcut for example Ctrl+D,Ctrl+E
    • Assign > OK

    select all text and hit the shortcut

    0 讨论(0)
提交回复
热议问题