Wicelo
Wicelo

Reputation: 2426

Is there a way to automatically escape backslashes when copy/pasting in Visual Studio?

I'm looking for a feature or extension similar to the one present in IntelliJ that escapes backslashes automatically while copy/pasting windows paths into the code. Are there any ?

Upvotes: 3

Views: 7113

Answers (2)

Cristian Diaconescu
Cristian Diaconescu

Reputation: 35681

ReSharper does it seamlessly but of course, it costs money.

There's also a free VS extension that does that, here: https://marketplace.visualstudio.com/items?itemName=martinw.SmartPaster2013

Upvotes: 4

AdrianHHH
AdrianHHH

Reputation: 14066

If you are pasting paths into strings in C# code then the language provides a string style where backslashes do not need escaping. Just prefix the string with an @ character. These two strings are the same:

string aaa = @"C:\some\path\to\a.file";
string bbb = "C:\\some\\path\\to\\a.file";

Upvotes: 4

Related Questions