migrating from MFC C++ 6.0 application to VS 2005 - c++

I have a big application developed in MFC C++ 6.0 and I want to migrate it to VS2005 and then, to VS2012. I'm looking for solve as much errors as I can, however I run into this situation:
I had a MFC C++ method: BOOL CPaginaModelo::OnRetirar_ItemLista() which returned a boolean value. So in many cpp files I use code like:
if (CPaginaModelo::OnRetirar_ItemLista())
{
<code>
}
For migration reasons, I have to change such method from BOOL to void, so the code should looks like:
CPaginaModelo::OnRetirar_ItemLista();
<code>
Since there are a lot of parts of the project files where this is used, is there any way by using search and replace with regular expressions in VS2005 to replace first expression to look like second expression?
Thanks for your help

Find and replace operation is not dependent on visual studio version. If you want use higher version of VS for this purpose then you just need to open particular VS and in find window replace window, replace parameter of "Look In" from entire solution to folder of your solution. This will allow you apply find and replace operation on certain folder.
To solved your issue, Multiline Search and Replace will help to complete replacement of your code with specific.

You could find and replace text in the Visual Studio editor by using Find and Replace (Ctrl+F or Ctrl+H) or Find/Replace in Files (Ctrl+Shift+F or Ctrl+Shift+H). For more details, I suggest you could refer to the link:https://learn.microsoft.com/en-us/visualstudio/ide/finding-and-replacing-text?view=vs-2019
You could also try to use .NET regular expressions to find and replace text in visual studio. For more details, I suggest you could refer to the link:https://learn.microsoft.com/en-us/visualstudio/ide/using-regular-expressions-in-visual-studio?view=vs-2019
As far as I'm concerned, Replacement couldn't make a symbol disappear, so { } may need to be removed manually.

Related

Vim regex equivalent in vs code

In Vim I can use :g/^\s*T\y A to copy all lines starting with T in a file to register a, then paste it to wherever I need it from said register.
How can I, or what is the equivalent regex to do the same in Visual Studio Code?
Be mindful that I am NOT fluent with regex and two days new to VS Code.
Thanks for your help in advance.
I don't think you can copy to multiple registers like that in VSCode unless someone has an extension to do it. Otherwise, one at a time you can:
Put ^\s*T.*$ in the search field
ALT-Enter will select all occurences of those matches
CTRL-C to copy to clipboard
Then paste to where you want it.

How to find all the #if conditions that surround a given line of C++ code?

I'm trying to untangle some code I didn't write. There are a lot of #if statements nested throughout this long file. I'd like a way to quickly identify all the #if statements that surround a given piece of code. Trying to search the Web for "#if" is hard since that either gets hashtags or ignores the punctuation, and "conditional preprocessor directives" didn't turn up anything other than a description of what they are.
Are there any commandline tools that already exist to find all the #ifs affecting a given line?
I'm using Visual Studio 2015 Pro. Are there any extensions that do that?
Not a proper answer but you can use sublime text editor.
In sublime you can select #ifby pressing ctrl + Done by one.
and if you want to find all press ctrl + f and type #if it will select all.
it want take too long to download it. you can download it from here. it is only about 8 mb in windows.

Visual studio find all Assert.IsTrue that have no message

I'm trying to find using visual studio regular expressions (https://msdn.microsoft.com/en-us/library/2k3te2cs.aspx) all calls to Assert.IsTrue that only pass the Boolean argument, for example Assert.IsTrue(parameter) would be one and Assert.IsTrue(parameter, "message") wouldn'
t.
For simple things, Assert.IsTrue\(([a-zA-Z ]+)\) does the trick, this works for the example provided above but not for things when there are evaluations done for example Assert.IsTrue(2 > 3). For this I tried using Assert.IsTrue\((.+[^,])\) so it matches everything that doesn't have "," but this only filters when the , is at the end, I'm not sure how to filter commas inside.
Finally, what I really want to do (which I'm not sure if it's possible with regular expressions alone) is to find Assert.IsTrue that have only one parameter but this parameter could be a method call, so it could have commas or not, something like Assert.IsTrue(isTrue(p1,p2))
I don't know why you want the solution to be programmatically, but if it's ok for you to have a Visual Studio based solution, you could just look for an example of Assert.IsTrue(parameter);, right click the method and select "Find all references`.
Remove the .+ from your second example and add a * also you should escape the period directly after Assert.
Assert\.IsTrue\(([^,])*\)
As for your expanded expression, something like this might work.
Assert\.IsTrue\(([a-zA-Z\.])*\(.*\)\)
This should let you find what you're looking for.

how to do vi search and replace within a range in sublime text

I enabled vintage mode on sublime text.. but there are some important vim commands that are lacking.. so let's say I want to do a search and replace like so
:10,25s/searchedText/toReplaceText/gc
so I wanna search searchedText and replace it with toReplaceText from lines 10 to 25 and be prompted every time (ie yes/no)..
how do I do this with Sublime Text? everytime I hit : it gives me this funny menu.. any way around that?
If you so much would like to see vim in action, try the other way around; ie enable sublime stuff in vim.
Here are 2 links that might come in handy:
subvim and vim multiple cursors (Which is one amazing feature in sublime that lacks in native vim).
Hope that gets you creative ;)
Unfortunately vintage mode does not understand ranges. The best way I know how to do this is with incremental search:
highlight the first occurrence of searchedText on line 10
hit cmnd/ctrl D to have Sublime find the next occurence
If you you want the next occurrence ignored, hit cmnd/ctrl K
Once you have highlighted all the occurrences, you can replace them all at once, as Sublime has left cursors behind on every occurrence you opted in on.
VintageEx gives you a Vim-like command-line where you can at least perform substitutions. Well, that's how far I went when trying it. I don't know how extended the subset of Vim commands it implements is but I'd guess that it's not as large as the original and, like with Vintage, probably different and unsettling enough to keep a relatively experienced Vimmer out.
Anyway, I just tried it again and indeed you can more or less do the kind of substitution you are looking for, which instantly makes ST a lot more useful:
:3,5s/foo/bar/g
:.,5s/bar/foo/g
:,5/foo/bar/g
:,+5/bar/foo/g
Unfortunately, it doesn't support the /c flag.
a plugin named vintageous offers more features including search function. It's available in package control
although this question is answered.. i figured this would add some value
the full functionality of vi search/replace is possible with the ruby mine IDE, once you install the ideavim plugin. The idea is perfect for ruby on rails by the way.

Easy way to add text above all methods in a solution in VS 2005?

A colleague was working on a Perl script to consume a C++ source file and add text above all of the methods in the file. He was looking to develop code using regular expressions from the ground up to detect the top line of the method:
void MyClass::MyMethod(int somethingOrOther)
Trying to do this from scratch is fraught with landmines, like discriminating the method headers from macros, comments, conditionals, etc.
This may be the really, really hard way to do things, as VS 2005 seems to be able to figure out exactly where all of the methods start and end (so that I can click on the box to collapse the method source).
Is there an easy way within the VS 2005 IDE to add some text above each method, solution-wide?
You can do a regular expression search and replace. Since you can place new lines into replace box, you can go nuts and do anything you want(except for extracting parameters). Example forthcoming.
Search string: ^:b*{:i}:b{:i}\:\:{:i}:b*{\(.*\)}
Replace string: ///Regex Example\n///Class: \2\n///Method: \3 returning \1\n\1 \2::\3\4
Code:
///Regex Example
///Class: Class
///Method: Foo returning void
void Class::Foo(int oneParam)
///Regex Example
///Class: Class
///Method: Bar returning void
void Class::Bar(int noParam)
I am not aware of a method of hooking into Visual Studio parser, unless you write a plugin, which might be a bit of an overkill.