Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. vc++ string Find problem

vc++ string Find problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
5 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    koo9
    wrote on last edited by
    #1

    hi all I got the text from the popupmenu item using GetMenuString like so: TCHAR itemText[MAX_PATH] = {0}; GetMenuString(m_hList,i,itemText,MAX_PATH,MF_BYPOSITION); then i try to find if certain sequence is in the itemText like so: TCHAR strTOSearch[2]="("; if(_tcsstr(itemText,strToSearch)!=NULL) { .... } now if the strToSearch does not contain any white space, it works fine, but then strToSearch[4]="h h"; then it won't find the string even though itemText does contain "h h", what am I missing? thx koo9

    R 1 Reply Last reply
    0
    • K koo9

      hi all I got the text from the popupmenu item using GetMenuString like so: TCHAR itemText[MAX_PATH] = {0}; GetMenuString(m_hList,i,itemText,MAX_PATH,MF_BYPOSITION); then i try to find if certain sequence is in the itemText like so: TCHAR strTOSearch[2]="("; if(_tcsstr(itemText,strToSearch)!=NULL) { .... } now if the strToSearch does not contain any white space, it works fine, but then strToSearch[4]="h h"; then it won't find the string even though itemText does contain "h h", what am I missing? thx koo9

      R Offline
      R Offline
      ryuki
      wrote on last edited by
      #2

      I did not used TCHAR yet. I did a simple test with strstr() and it worked. char tst[50]; strcpy(tst,"Hello you!\nThis works!"); // put a string into tst if (strstr(tst,"lo y")) // strstr returns NULL if there is no ocurance m_output="OK"; UpdateData(FALSE); The str-functions are pretty old and are not very object orientated but they don't let you down. I like them. ;)

      K 1 Reply Last reply
      0
      • R ryuki

        I did not used TCHAR yet. I did a simple test with strstr() and it worked. char tst[50]; strcpy(tst,"Hello you!\nThis works!"); // put a string into tst if (strstr(tst,"lo y")) // strstr returns NULL if there is no ocurance m_output="OK"; UpdateData(FALSE); The str-functions are pretty old and are not very object orientated but they don't let you down. I like them. ;)

        K Offline
        K Offline
        koo9
        wrote on last edited by
        #3

        strstr and _tcsstr both works fine in ur case, I guess it's just my itemText from teh GetMenuString call, it's supposed to be LPTSTR, but I use TCHAR, then _tcsstr or strstr will cast it to char * in fact, const unsigned short * in the function, I guess that's why it does work. but not sure how get cast them correctly.

        R 1 Reply Last reply
        0
        • K koo9

          strstr and _tcsstr both works fine in ur case, I guess it's just my itemText from teh GetMenuString call, it's supposed to be LPTSTR, but I use TCHAR, then _tcsstr or strstr will cast it to char * in fact, const unsigned short * in the function, I guess that's why it does work. but not sure how get cast them correctly.

          R Offline
          R Offline
          ryuki
          wrote on last edited by
          #4

          The best solution would be to use CString. It has many constructors. For LPCTSTR you can use CString::CString( LPCTSTR lpch, int nLength ) and for searching a substring or a character Value in another String use CString::CString::Find(...). Just check the CString class and you will see. If it still not work than look at the return value of GetMenuString. Maybe it redrives not the whole string (don't think so).

          K 1 Reply Last reply
          0
          • R ryuki

            The best solution would be to use CString. It has many constructors. For LPCTSTR you can use CString::CString( LPCTSTR lpch, int nLength ) and for searching a substring or a character Value in another String use CString::CString::Find(...). Just check the CString class and you will see. If it still not work than look at the return value of GetMenuString. Maybe it redrives not the whole string (don't think so).

            K Offline
            K Offline
            koo9
            wrote on last edited by
            #5

            GetMenuString return the full text, I will give it a try. thx

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups