Click to See Complete Forum and Search --> : Visual Studio: Find & Replace w/ Expressions?
MrDoomMaster
September 22nd, 2005, 05:56 PM
I don't know about you guys but trying to use expressions in Find & Replace in Visual Studio .NET 2003 is just like trying to learn a new programming language.
I'm particularly interested in changing every occurance of this code:
CHECKCLASS();
return 0;
into this code:
CHECKCLASS();
Can someone show me how I can format the Find & Replace expression in order to achieve this? MSDN fails to provide any examples.
Thanks!
Note: All spaces must remain the same, as the tabbing shown above is essential. My tabs are spaces, not actual tabs. 4 spaces per tab.
wildfrog
September 22nd, 2005, 07:12 PM
Maybe this does the trick:
// What to find
\tCHECKCLASS\(\);\n\t\treturn 0;\n
// Replace with
\tCHECKCLASS();\n
Basically what is says is to find a tab followed by "CHECKCLASS();", a new-line, two more tabs, "return 0;" and then a new line. Then replace it with a tab followed by "CHECKCLASS();" and a newline, phew...
- petter
MrDoomMaster
September 22nd, 2005, 07:42 PM
hmm didn't work. Perhaps \t doesn't consider 4 spaces as a tab.
wildfrog
September 23rd, 2005, 03:42 AM
Sorry... not tabs, just spaces.
^:Wh^4CHECKCLASS\(\);\n:Wh^8return:Wh0;\n
This should find a newline, 4 spaces, "CHECKCLASS();", newline, 8 spaces, "return 0;" and a newline...
- petter
Marc G
September 23rd, 2005, 05:33 AM
BTW: these are called regular expressions and are explained in the MSDN. :wave:
MrDoomMaster
September 23rd, 2005, 12:49 PM
BTW: these are called regular expressions and are explained in the MSDN. :wave:
The expressions are explained but no examples are given. I need MSDN to provide me syntax examples, so that I can get an idea of how to use them. This is the entire point of posting this thread, to obtain examples.
MrDoomMaster
September 23rd, 2005, 12:50 PM
Sorry... not tabs, just spaces.
^:Wh^4CHECKCLASS\(\);\n:Wh^8return:Wh0;\n
This should find a newline, 4 spaces, "CHECKCLASS();", newline, 8 spaces, "return 0;" and a newline...
- petter
Why the ^ at the start?
Marc G
September 23rd, 2005, 02:02 PM
Why the ^ at the start?
It means the start of a line.
BTW: the following pages explains all the symbols, including the ^ ;)
http://msdn2.microsoft.com/en-us/library/2k3te2cs
MrDoomMaster
October 7th, 2005, 11:32 AM
I'm trying a new type of find/replace, and it's not working so far. When I click "FIND", it actually DOES match the find expression, but if I click REPLACE ALL, an error appears saying "Syntax error in pattern". Not very helpful...
FIND: DXLIBFAILURE\({:i}\)
REPLACE: DXLIBFAILURE\(\0, __FUNCTION__, __LINE__\)
Any help? Thanks.
:::EDIT:::
I just fixed it. The proper notation:
FIND: DXLIBFAILURE\({:i}\)
REPLACE: DXLIBFAILURE(\1, __FUNCTION__, __LINE__)
no \( or /) is allowed in a replace expression because there are no sub-expressions to group.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.