CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Jul 2011
    Posts
    33

    Resolved [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
    Last edited by p_zshk; August 4th, 2011 at 10:08 PM. Reason: resolved

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    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!)
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Jul 2011
    Posts
    33

    Re: Need to Check for a particular string

    i am a noob in vc++.. can you please elaborate it further.

    regards.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Need to Check for a particular string

    Define "content".

  5. #5
    Join Date
    Jul 2011
    Posts
    33

    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".

  6. #6
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    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.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  7. #7
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Need to Check for a particular string

    Quote Originally Posted by Eri523 View Post
    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?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  8. #8
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Need to Check for a particular string

    Quote Originally Posted by VladimirF View Post
    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.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  9. #9
    Join Date
    Jul 2011
    Posts
    33

    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..??
    Last edited by p_zshk; August 3rd, 2011 at 10:28 PM.

  10. #10
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Need to Check for a particular string

    In this case VladimirF had the right instinct () 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.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  11. #11
    Join Date
    Jul 2011
    Posts
    33

    Re: Need to Check for a particular string

    thanks...Eric and Vladimir...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured