使用Visual Studio删除文本中的空行 [英] Remove empty lines in text using Visual Studio

查看:195
本文介绍了使用Visual Studio删除文本中的空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Visual Studio中删除空行?

How to remove empty lines in Visual Studio?

推荐答案

它非常有用,特别是如果您要排列或比较代码,感谢回答此问题的人,我从此处,并希望与Stackoverflow共享:

It's very useful especially if you want to arrange or compare codes, thanks for the people who answer this question, I've got the answer from here and would like to share it with Stackoverflow:

Visual Studio可以使用正则表达式在替换操作中删除空行.

Visual Studio has ability to delete empty lines in replace operation using regular expressions.

  • 单击 Ctrl - H (快速替换)

勾选使用正则表达式"

Tick "Use Regular Expressions"

在查找"中指定^$\n

在替换"框中删除所有内容.

In Replace box delete everything.

单击全部替换"

所有空行将被删除.

空行的正则表达式由

^

行尾$

换行符\n

请注意,通常在Windows中,由2个字符表示的行尾-回车符(CR,ASCII 13,\r)换行符(LF,ASCII 10,\n).

Note that normally in Windows an end of line indicated by 2 characters crlf - Carriage Return (CR, ASCII 13, \r) Line Feed (LF, ASCII 10, \n).

一个正则表达式,用于删除确实不是空白的空白行(即它们没有空格):^:b*$\n

A regex to remove blank lines that are/aren't really blank (i.e. they do/don't have spaces): ^:b*$\n

要删除双行:^:b*\n:b*\n替换为:\n

To remove double lines: ^:b*\n:b*\n replace with: \n

*对于Visual Studio 2013及更高版本:*

^\s*$\n

,对于双行:

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

请在下面的@lennart的答案中查看VS2012及更高版本的正则表达式语法更新

See the regular expression syntax updates for VS2012 and above in @lennart's answer below

这篇关于使用Visual Studio删除文本中的空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆