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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. LPWSTR substring?

LPWSTR substring?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
4 Posts 4 Posters 0 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.
  • T Offline
    T Offline
    ting668
    wrote on last edited by
    #1

    HI~ How to search a substring from LPWSTR? Also I cannot extract a character like string class e.g I cannot do this: LPWSTR a_string = _T("abcdef") if (a_string[2] == 'c'){...} How to extract a character is the string is LPWSTR type? Thanks

    D A 2 Replies Last reply
    0
    • T ting668

      HI~ How to search a substring from LPWSTR? Also I cannot extract a character like string class e.g I cannot do this: LPWSTR a_string = _T("abcdef") if (a_string[2] == 'c'){...} How to extract a character is the string is LPWSTR type? Thanks

      D Offline
      D Offline
      Dimitris Vasiliadis
      wrote on last edited by
      #2

      LPWSTR a_string = _T("abcdef"); if (a_string[2] == (WCHAR)'c'){...}


      ...Plug & Pray... X|

      M 1 Reply Last reply
      0
      • D Dimitris Vasiliadis

        LPWSTR a_string = _T("abcdef"); if (a_string[2] == (WCHAR)'c'){...}


        ...Plug & Pray... X|

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        Dimitris Vassiliades wrote: (WCHAR)'c' Actually the correct syntax is L'c' for wide-char literals. (Your code will work but I didn't want the original poster to get the idea that casts are the solution for string-related stuff.) --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- Actual sign at the laundromat I go to: "No tinting or dying."

        1 Reply Last reply
        0
        • T ting668

          HI~ How to search a substring from LPWSTR? Also I cannot extract a character like string class e.g I cannot do this: LPWSTR a_string = _T("abcdef") if (a_string[2] == 'c'){...} How to extract a character is the string is LPWSTR type? Thanks

          A Offline
          A Offline
          Archer282
          wrote on last edited by
          #4

          LPCTSTR SubString( LPCTSTR lpExpression, // [in] Pointer to a string to extract the substring from ULONG nStart, // [in] Starting point LONG nLength = -1 ) // [in] how far to go from the startig point, use -1 to go the end of lpExpression { if( nLength < 0 ) nLength = strlen(lpExpression) - nStart; ULONG nPos = 0; PTCHAR lpResult = new TCHAR[512]; for( ULONG i = nStart; i < (ULONG)(nStart+nLength); i++ ) { // put the current char from lpExpression into lpResult lpResult[nPos++] = lpExpression[i]; } // add the null byte to lpResult; lpResult[nPos] = '\0'; // return the substring return lpResult; }

          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