Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

You can find single / in VS2013 with the following using :

  • type Ctrl+f
  • in the search box, type (?<!/)/(?!/)
  • under the search box, click on the icon representing .*
  • select Entire Solution
  • Launch the search

But, you must know that the result will be not what you really want, because, you will find XAML code, URL, ...

Try this regex expression:

[^/<]/[^/>]

"Not a slash followed by a slash followed by not a slash"

A regular expression search for (?<!/)/(?!/) should find only single slashes, by using zero-width negative lookbehind/lookahead assertions. The .* button in the small find dialog turns on regular expression searches. There is a checkbox under "Find options" for the full search dialog (Ctrl+Shift+F).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top