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:
$
as my regular expression{get; set;}
as my replacement textThis 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?
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 .
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.
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.
Select the text with the line-breaks, then CTRL+J and they are removed.
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.
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.
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.
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.
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.
I couldn't come up with some thing more easier than this
Find this .. \r\n
and replace it with {get;set;}\r\n
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With