[RESOLVED]Need to Check for a particular string
Hi,
I have a method LogFileContent(BSTR content).
I need to check the value which is present in content. I need to check for "Waiting for free XE Slot". If this string is present in content, i need to perform some executions.
How can I achieve this?
Regards
Re: Need to Check for a particular string
IIRC you can treat a pre-existing BSTR just like an LPCWSTR. (Or as an LPWSTR if you want to modify it, but never change its length that way!)
Re: Need to Check for a particular string
i am a noob in vc++.. can you please elaborate it further.
regards.
Re: Need to Check for a particular string
Re: Need to Check for a particular string
content is of type BSTR... that will hold some text like "Waiting for free XE Slot" or "Successfully completed".
Re: Need to Check for a particular string
You can use the wcscmp() function to compare the two strings. It returns 0 if they are equal:
Code:
if (!wcscmp(content, L"Waiting for free XE Slot")) {
// The strings match!
}
And, to clarify that in advance, note that this test only passes if the two strings are exactly identical.
Re: Need to Check for a particular string
Quote:
Originally Posted by
Eri523
You can use the
wcscmp() function to compare the two strings. It returns 0 if they are equal:
Code:
if (!wcscmp(content, L"Waiting for free XE Slot")) {
// The strings match!
}
And, to clarify that in advance, note that this test only passes if the two strings are
exactly identical.
wcsstr?
Re: Need to Check for a particular string
Quote:
Originally Posted by
VladimirF
Yes, of couse, as an option for the case that an exact match is not required. And as I interpreted the OP, it is. The closing sentence of my post was just to make sure wcscmp() is not the function of choice in case an exact match is not required.
Re: Need to Check for a particular string
actually my content will hold some extra text too...like "'Extraction ID: EBS_XE_1265635755_3326
Waiting for next XE free slot (20)
". out of which i need to match just the "Waiting for free XE Slot".
it is somewhat i need to do a pattern matching what we do in Oracle. My content will hold a longer text. of which I need to match for whether that text has "Waiting for free XE Slot" as a part of it or not...
How can i achieve this..??
Re: Need to Check for a particular string
In this case VladimirF had the right instinct (:thumb:) and the function he suggested (and linked to its MSDN documentaion) is exactly what you need. It will return a pointer to the found partial string or NULL if it wasn't found. You're not actually interested in the location of the search hit, so check whether the return value is != NULL. If it is, the string you probed for is contained in the string you checked.
Re: Need to Check for a particular string
thanks...Eric and Vladimir... :)