Searching and finding word within string in C++/CLI - c++-cli

everyone.
I need your help. I am writing gui application in C++/CLI with VisualStudio 2017. I want to search and find a word within string.

You're referring to managed String objects. SO this is just worth to google it.
String^ text = "I love apple";
bool result = text->Contains("apple");
Full documentation here in the MSDN

Related

Migrating a string table (binary .res file) from VB6 to VB.NET

I have to port an old VB6 program to VB.NET and stumbled across an old ".res" (Resource) file, which is stored in binary format. Using VS 2013, I can embed that file into my .NET project, and VS shows me that it contains simply a string table.
The problem is, I cannnot figure out how to bring those res file into a more modern text format, or how to load the strings directly from the res file. I linked file to my application es an embedded resource, but all my atttempts to use VB6.LoadResString from the "Visual Basic Compatibility library" lead to an exception, showing the key was not found.
Furthermore, it seems VS does not allow me to copy/paste the string table into a text file, at least, not at a whole. Actually, it allows me to copy/paste one string after another, but as you can imagine, that is extremely cumbersome and error-prone. That is why I am looking for a better solution. Any ideas?
There is a functional VB6 Class for doing this at:
ResDecomp Class Decompiles RES Files
Sample programs are included, one of them a sort of "viewer" and the other just extracts RT_STRING resource strings to an XML document. You could easily change the latter to dump the string values to a text file, database, etc. instead.
Embed the .res file to a simple VB6 program which loops from min to the max ID and write out the strings to a text file using LoadResString (error trap for missing IDs).

VBA and late binding: Where do I find the numeric equivalents to constants?

I'm a complete VBA newbie, having decided to teach myself over a weekend, so forgive the stupid question(s). I'm trying to automate some routine tasks involving generating Word documents or emails from an Excel Spreadsheet. Because there will be multiple software versions involved, I am using late binding to open Word and Outlook. My question is: Where can I find a simple reference telling me what the index numbers are that correspond to the application constants? I have killed a lot of time googling to learn that, for example, the Outlook foldertype for "Contacts" is "10". Maybe someone knows of a web link that could save me countless hours of searching?
Update: http://msdn.microsoft.com/en-us/library/office/gg278936%28v=office.14%29.aspx seems to have some of the information I need, although it's not always intuitive where the information is. For example, if it contains the outlook folder type constants, I haven't found them yet.
See here
Enumeration http://msdn.microsoft.com/en-us/library/office/ff860961(v=office.15).aspx
OlDefaultFolders Enumeration http://msdn.microsoft.com/en-us/library/office/ff861868(v=office.15).aspx
I would recommend to add the relevant object libraries to your project as References during development time. You do this by using the Tools - References Menu in the VBA Editor. This makes developing a lot easier as you can use intellisense while writing the code.
If you need only a few Enums or single Constants in your code the easiest way to get their values is to hit [F2] in in VBA Editor while the object libraries are still referenced. Then search for the constants name and copy its value to your code.
Just using the numeric values of the constants in your code makes the code pretty hard to read. So I would recommend to re-declare all the Enums/Constants you actually use in a module in your own project. That massively improves the readability of your code.
So, instead of just copying the value from the VBA Object Browser, I suggest you copy the name and the value and put it your own code as a constant declaration. For your example of the Outlook contacts folder this will look like this:
Public Const olFolderContacts = 10
You can then use the constant in your procedures as you would do with Early Binding.
Should you work on a larger automation project using many of the constants from any one of the Office Object Libraries, you can download ready-made VBA modules containing all the Office constants from my website. You can then just import the relevant modules into your project and are ready to go.
After you finished the main development work, you remove the linked libraries from your project and declare the relevant object variables As Object instead of the actual type.
Always remember to compile your project not to miss any declaration that does not work late binding.

Finding text in a document

I have documents in which I need to find the text "MM" followed by three integers and compile that into a list. Each document has different sets of numbers, but it always follows this format.
Can I utilize a MS-Word VBA code to do something like this? If so... how?
I think i have just the thing for you to highlight these patterns without macros or coding required.
use the find and replace dialog in WORD and configure it like so:
The magic is this expression:
<MM[0-9]{3}>
see more syntax here:
http://www.gmayor.com/replace_using_wildcards.htm
I did it here in Word 2010 and it works perfectly.
picks up
MM123
MM232
and skips
MM2f1
MM2323
Edit: if you're trying to compile it into a separate list in addition to highlighting it in the doc, I'd suggest you save a copy of the doc as a plaintext file, then write a really simple shell script or console application to grab the strings you're looking for.
do you know regular expressions? (also called regex)?
This is a way to perform searches based on varying search patterns. Very easy, as you just need to use your usual search window. Just change the search pattern according to some rules. An introduction for regex in Word is available here:
http://www.svprogramming.net/regent/documentation/Microsoft-Word-Wildcards-as-Regular-Expressions.html
Good luck!

Search for a string in a collection of dlls

We have a number of dlls in a single directory. Most, but not all, are C++ resource dlls only. These dlls can be opened in Visual Studio for a "visual" inspection (you can see the "String Table").
Here's the scenario, we are looking for a particular string but we don't which DLL contains the string. Is there a tool that we can use that will perform a string search on DLLs?
Thanks!
You can use the findstr command to search strings in several files.
I've just successfully used .NET Reflector 6 to find a string (using Ctrl+S) in the list of loaded DLLs.
Slightly off for the original question (concerning C++) but I've stumbled upon this question by the title and this is my answer.

How to list all files of a given folder (recursively through sub-folder)?

I'm writing a microsoft word macro and having difficulty with vb.net. Please help.
Check out the answers here - VB6 is almost identical to VBA.
You will need to add a reference to the Microsoft Scripting Runtime if you want to use FileSystemObject
Or you can just drop in the CDirDrill class which means you won't need any external references.
A Word Macro is usually written in VBA rather than VB.Net, I'm assuming that you meant VBA?
Use the FileSystemObject to access the filesystem and then use recursion to "walk" down. Here's a sample:
http://www.java2s.com/Code/VBA-Excel-Access-Word/File-Path/RecursiveSearchusingtheFileSystemObjectModel.htm
If it's actually VB.Net you're using, the idea will be the same but use System.IO.Directory rather than the FileSystemObject.
I personally like the FileSystemObject approach. i normally set up a recursive search function like the one found here and have never had any problems.