user2075599
user2075599

Reputation:

How to remove line endings on multiple lines in visual studio 2012

In the visual studio 2012 editor, I don't need to remove entire or multiple blank lines as all of the other stuff I could search on S/O is concerned with. I want to select multiple lines of aspx markup (usually from 2 to 10 or so) and remove the line endings on multiple lines of source code so that you end up with everything that was in the selected lines on one line. A small example of what I want to do is:

BEFORE source code:

[dx:GridViewTextColumn ID="Inactive" 
    Width="50"]
[/dx:GridViewTextColumn]

AFTER:

[dx:GridViewTextColumn ID="Inactive" Width="50"][/dx:GridViewTextColumn]

(replace the "[" chars above with "<" chars, and "]" with ">" chars, I entered it that way just to get it to display somewhat properly here)

It seems like this should be pretty simple, but I have tried various search/replace and regex values that are talked about in the many articles that talk about removing entire blank lines, but can't get anything to work. A little help? :)

** 2014-02-06 at 2306 hrs update:

Still trying, but this gets me really close:

In Visual Studio 2012 ide. Working in an aspx file with its xml markup. Do Ctrl-H to do a string search/replace on a selected stretch of xml (from start to finish of a particular well-formed tag, which may or may not contain subtags, but each tag is on a separate line). Specify the following in the from textbox:

\s{2,}

Specify one blank space in the to textbox.

For the first example I gave, the result would be:

[dx:GridViewTextColumn ID="Inactive" Width="50"] [/dx:GridViewTextColumn]

Note the single blank space between the separate tags (after the first ']' character and before the second '[' character) . If I could figure out how to not have that space in the result it would be perfect.

** 2014-02-06 at 2322 hrs update:

Oh duh. Otay, I think I got it, the from textbox value is the same, but for the to textbox value, instead of a single space, just have nothing. That seems to work for my specific use case (selecting a certain amount of xml within aspx markup and making it all be on a single line with no extraneous blank spaces). Yay!

Upvotes: 0

Views: 1105

Answers (1)

user2075599
user2075599

Reputation:

In the VS2012 ide, Ctrl-H dialog, specify regex, then in the from textbox put:

\s{2,}

and in the to textbox put nothing.

Execute on whatever amount of xml that you have selected (from the beginning tag less-than character to its matching ending tag greater-than character, along with any/all subtags in between, over any number of lines of source code).

What you have selected will be condensed to one line of source code without any extraneous blank spaces present.

This seems to work for the xml that is in .NET aspx markup (what I specifically needed); not guaranteed to work anywhere else.

Upvotes: 3

Related Questions