Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make Visual Studio find only single slashes and not double slashes?

To add more precision to floating point numbers, I have to go through a bunch of C# classes and, wherever there is a division operation, multiply both the numerator and denominator by 1000. So suppose we have a numerator, n and a denominator, d. Then the original would look like this: n / d. And I would need to change it to (n*1000)/(d*1000).

To search for all the division operators I'm using the find function (ctrl+f) in Visual Studio 2013 Ultimate. I'm searching for all '/'. The problem is that the find function also picks up the slashes in the comments. How can have the find function only find the single slash '/' and not the double slash '//'?

Thank you for any suggestions.

like image 879
navig8tr Avatar asked May 12 '14 15:05

navig8tr


1 Answers

Good

Regex find (Ctrl+Shift+F with the Use Regular Expressions option checked) [^/<]/[^/>] in your solution - basically a / that:

  • is not preceded by another / or a < (i.e. closing XML comment tags like </para>)
  • is not followed by another / or a > (i.e. standalone XML comment tags like <see cref="Foo"/>)

The only false positives I see with this approach in a quick check against a solution of ~80 projects are...

  • Dates (e.g. 1/1/2014)
  • / in comments (e.g. Note that an up/down change....)

...but others could come up depending on your code base - for example:

  • URLs (e.g. http://stackoverflow.com/users/1810429/j0e3gan)
  • XPaths (e.g. /Customer/Address/City/text())

Better

If you consistently put spaces between the division operator and its operands, you could tighten the regex a bit to alleviate these false positives, changing it from...

[^/<]/[^/>]

...to...

[^/<] +/ +[^/>]

...where + will match one or more spaces of course.

like image 70
J0e3gan Avatar answered Sep 28 '22 02:09

J0e3gan