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?
Printable View
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?
LPTSTR mystring;
std::string s = mystring;
// Repeat as above
:)
Don't fall into the C trap - this is C++!
What would be the easiest way to parse the string contents after "/m=" to a different string if found?
.substr!
std::string s = "/m=blablabla";
std::string s2 = s.substr(3);
There you have everything after the "/m=" (at least I hope).
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.
Ah, no, LPTSTR is actually TCHAR* (aka TSTR*).
Grr to Microsoft typedefs. They confuse and disorient :/
Sorry. Daved is right.
This is the typedef I usually use (that way you don't need an #if #else block):
Code:typedef std::basic_string<TCHAR> Tstring;