0

It's occurred to me that I moderately frequently want to find values that are defined as strings in my codebase.

Mostly in contexts where I suspect there's some string-based reference to a Method/Prop that I've renamed (). Or occasionally when I want to find "this kind of SQL expression in hand-built SQL queries".

Obviously there are all sorts of pitfalls that could arise from assuming such a search has found every relevant piece of code ... but it would still be a useful thing to be able to search.

Natually Rider knows whether any given sequence of characters is inside a string or not ... indeed, if I just search for the characters, then in the results window it shows contextual highlighting to indicate if a value is a string ... so ...

Q: Is there a way to restrict a Rider text search to return only results where the string is found in a string literal?

Brondahl
  • 7,402
  • 5
  • 45
  • 74
  • I don't know if you are relying on magic strings which you shouldn't. Also, I don't know if rider supports that kind of search. But it supports regex search, you can use a regex like `"(.*?)"` to search between quotes. You can extend the regex to exclude comments etc. – Eldar Dec 07 '22 at 09:12
  • @Eldar Except "Inside a string" and "between 2 quote marks" aren't the same thing. e.g. searching for `".*and.*"` would return a false positive on the first sentence of this comment. Similarly multi-line strings will break the search, unless you include line breaks in the regex `.`, ... at which point 50% of the codebase is going to start getting hit, because the regex can't tell what's inside, and what's outside. – Brondahl Dec 07 '22 at 09:16
  • Well, you are trying to narrow down the search results, and regex provides you a way to do it. If you are seeking assignments you can utilize the assignment operator etc. You can use multiline searches by combining `.` and `\n`. And the first sample you gave I don't think it's a common scenario in a regular language like C#. – Eldar Dec 07 '22 at 09:49

1 Answers1

3

There's filtering in "Find in files" (find all) feature: enter image description here

Gawo He
  • 155
  • 5