Usually Find/Replace gets the job done for what I need, although sometimes using “Replace All” can break more stuff that it fixes.
But today I had this function I wanted to get rid of and simple change it with a public variable.
So I had something like this.
object->setLayer(/*BLABAL BLA CODE, */);
I want to replace it with something more simple
object->Z = /*BLABAL BLA CODE, */;
So using Visual Studio Find/Replace in regular expressions mode I used this as a search string
And this as a Replace with string
Now, notice the first one, it’s actually simple, you have “setLayer”, followed by “\(” to tell the expression we really need to be that character, after than we have “.+”, which means match any single character except a line break and at least one occurrence. Followed by “\);”
Now if you notice we have curly brackets around the inside of what the function receives as parameter, that’s because we are tagging that string to use it later.
This way on the replace we simply need “Z=” followed by the first tagged string we have “\1”. if we have more curly brackets it would be “\2”, “\3” etc.
Check the full list for more options: http://msdn.microsoft.com/en-us/library/2k3te2cs%28v=vs.80%29.aspx
Cool thing. But only if you not use ReSharper 6.1 and its cool feature Pattern Search and Replace. You can easy and intuitive replace more complicated code with avare of namespaces, etc. It is not an advertising. I am just a fan of R#
Yeah, but from what I can tell ReShaper is for C# only and I mostly code in native code, C++ 🙂
doesn’t work , need help!!!
i want to find:
and to replace with:
x-can be all string