Finding a quoted string

I am trying to write a macro for Visual Studio that will search my source code and put a bookmark on all quoted strings that the first character is not an underscore (_).

I have written many macros but this one is giving me a problem, I cannot get it to escape the " in my search string. I can perform the search manually, but cannot get the macro to work. Any Ideas? I am sure it is just a matter of specifying the correct FindWhat string, but I have tried everything I can think of and nothing works.

Here is the macro -

Sub FindNonConformingStrings()

DTE.ExecuteCommand("Edit.Find")

DTE.Find.Target = vsFindTarget.vsFindTargetCurrentProject

DTE.Find.MatchCase =True

DTE.Find.MatchWholeWord =True

DTE.Find.MatchInHiddenText =True

DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr

DTE.Find.FilesOfType ="*.cpp"

DTE.Find.FindWhat ="\"[!_]*\""

DTE.Find.Action = vsFindAction.vsFindActionBookmarkAll

DTE.Find.Execute()

DTE.Windows.Item(Constants.vsWindowKindFindReplace).Close()

EndSub

[1793 byte] By [RaymondSanders] at [2007-12-24]
# 1

I believe your regex is the problem. Switch it to

"\"[^_][^"]*\""

JaredParsonsMSFT at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
That didnt help. The VB IDE gives an error on it saying an "Identifier was expected" on the first carat (^). It just seems to not be ignoring the first escaped quote, and thinking it is finishing the string. Any other ideas?
RaymondSanders at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

forgot a couple of required quotes...change it to:

"\""[^_][^""]*\"""

I tested your code on VB files and it works for me with the above change!

DMan1 at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4
Actually it steps thorugh and finds the strings...but when running the full code it does not bookmark them...I've an idea...be back in a minute...
DMan1 at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5

actually you have to call the findnext method for it to work correctly on the run...this tested sat:

DTE.Find.FindWhat = "\""[^_][^""]*\"""

DTE.Find.Action = vsFindAction.vsFindActionBookmarkAll

Dim result As EnvDTE.vsFindResult = DTE.Find.Execute()

DTE.ExecuteCommand("Edit.FindNext")

DTE.Windows.Item(Constants.vsWindowKindFindReplace).Close()

DMan1 at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 6
This still did not work completely. It does not place any bookmarks at all. It does set the cursor to the first occurance, and if I press F3 it will jump to the next occurance correctly and I can cycle through them that way. I dont know if it makes a difference, but I am running this macro inside of VC++ 2005 standard edition to search my C++ source code. Any other ideas? I really would like the bookmarks so I can tell what I have checked and what I have not checked.
RaymondSanders at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...