I want to find out if the string "/m=" is in tempPrinterName anywhere. Would wcscmp(L"/m=", tempPrinterName) be the best way of doing so? If not, what would you suggest?
I want to find out if the string "/m=" is in tempPrinterName anywhere. Would wcscmp(L"/m=", tempPrinterName) be the best way of doing so? If not, what would you suggest?
Since this is the C++ forum I'll assume tempPrinterName is a C++ wstring. If so, use the find member function:If you need to find the position in the string then just save the return value of find as a std::wstring::size_type.Code:if (tempPrinterName.find(L"/m=") != std::wstring::npos) { // found }
what if tempPrinterName is also a LPTSTR? How would I find that string using C-style methods?
What would be the easiest way to parse the string contents after "/m=" to a different string if found?
If tempPrinterName is an LPTSTR, then you might not want to use string, you might want to use some typedef that will be either string or wstring depending on whether you're using UNICODE or not. Also, if you're using LPTSTR, then you should be using _T("/m=") instead of L"/m=". (If your application definitely uses or does not use unicode then you can just pick the appropriate string and use L"" or "".)
To get the string after the "/m=", use the result of find. Since "/m=" has three characters, then pass the result of find + 3 to substr.
This is the typedef I usually use (that way you don't need an #if #else block):
Code:typedef std::basic_string<TCHAR> Tstring;