Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Search and Replace Line Endings

Tags:

In Visual Studio 2015 I want to add text to the end of every line of a selected block of text. The regex approach I'm using is almost working, but not quite.

Here is sample code I want to modify:

public string nameOfGeometry public string color public string density 

All three of the above lines need to end either with a semicolon, or perhaps auto-implemented properties. Here is what I tried:

  1. Select all the text I want changed, and press ctrl-h.
  2. Toggle "on" regular exressions
  3. Enter $ as my regular expression
  4. Enter {get; set;} as my replacement text

This does exactly what I want, except that it insert a carriage-return (CRLF) between the $ and the replacement text. In other words, my example shown above transforms into this:

public string nameOfGeometry {get; set;} public string color {get; set;} public string density {get; set;} 

How do I accomplish this, without the CRLF being added?

like image 655
Brent Arias Avatar asked Dec 19 '15 00:12

Brent Arias


People also ask

How do I find and replace new line in Visual Studio?

Today I learned How to find and replace with a newline in Visual Studio Code. In the local searchbox ( Ctrl + F ) you can insert newlines by pressing Ctrl + Enter . If you use the global search ( Ctrl + Shift + F ) you can insert newlines by pressing Shift + Enter .

How do I find and replace multiple lines in Visual Studio?

CHANGE: The default keyboard shortcut for “Multiline Find/Replace” was Ctrl+Alt+F but it was not applied because this shortcut was already taken by “F# Interactive”. So, the new default shortcut is Ctrl+M, Ctrl+F.

How do I insert a new line in Find and Replace?

Select the cells that you want to search. On the keyboard, press Ctrl + H to open the Find and Replace dialog box, with the Replace tab active. On the Replace tab, click in the Find What box. On the keyboard, press Ctrl + J to enter the line break character.

How do you remove carriage returns in Visual Studio?

Select the text with the line-breaks, then CTRL+J and they are removed.

How are line endings interpreted in Visual Studio?

Encodings and line endings. The following characters are interpreted as line breaks in Visual Studio: Text that is copied from other applications keeps the original encoding and line break characters. For example, when you copy text from Notepad and paste it into a text file in Visual Studio, the text has the same settings that it had in Notepad.

How do I find and replace in Visual Studio Code?

Find and Replace control Press Ctrl + F as a shortcut to find a string in the current file. Press Ctrl + H as a shortcut to find and replace a string in the current file. The Find and Replace control appears in the upper right corner of the code editor window.

How to get rid of newlines in VS Code?

The latest version of VS Code has a shortcut to remove breaks from selection ( CTRL + J ). Show activity on this post. I found that (at least on Windows) the solution was to use search and replace with a regular expression. Search for $ and replace with nothing to get rid of the newlines.

How do I replace a line with another line?

Show activity on this post. Select the new line, and press ctrl + D (and hold it). Then press ctrl + h, you will be able to replace it with whatever you need. Show activity on this post. Torn on regex mode and find and replace.


2 Answers

I did this and it works

Find: ([^\r\n]+)
Replace: $1 {get;set;}

Also
Find: \r\n
Replace: {get;set;}\r\n

But still I have no idea why it has to be this hard. Still looking for someone come up with simpler solution.

like image 97
TLJ Avatar answered Sep 22 '22 04:09

TLJ


I couldn't come up with some thing more easier than this

Find this .. \r\n and replace it with {get;set;}\r\n

like image 31
Angloos Avatar answered Sep 19 '22 04:09

Angloos