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. Comparing a character string to LPWSTR

Comparing a character string to LPWSTR

Scheduled Pinned Locked Moved C / C++ / MFC
questionlearning
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.
  • A Offline
    A Offline
    abhinarulkar
    wrote on last edited by
    #1

    Hi all, I need to compare 2 strings,one is a simple character string and the other is a LPWSTR value.How can I do it.Is there any type conversion available. Thanks Abhishek. Learning is a never ending process of Life.

    P L 2 Replies Last reply
    0
    • A abhinarulkar

      Hi all, I need to compare 2 strings,one is a simple character string and the other is a LPWSTR value.How can I do it.Is there any type conversion available. Thanks Abhishek. Learning is a never ending process of Life.

      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      You will need to convert one of the strings into the same format as the other. Which one you choose does not matter. Use one of these functions: MultiByteToWideChar WideCharToMultiByte


      Build a man a fire, and he will be warm for a day
      Light a man on fire, and he will be warm for the rest of his life!

      B 1 Reply Last reply
      0
      • P Paul M Watt

        You will need to convert one of the strings into the same format as the other. Which one you choose does not matter. Use one of these functions: MultiByteToWideChar WideCharToMultiByte


        Build a man a fire, and he will be warm for a day
        Light a man on fire, and he will be warm for the rest of his life!

        B Offline
        B Offline
        Bart Robeyns
        wrote on last edited by
        #3

        Isn't it best to convert the single-byte to wide-format? If conversion from wide- to single-byte format looses information (because some widechars are not representable), the strings might match after conversion, even if they don't actually match... No?

        1 Reply Last reply
        0
        • A abhinarulkar

          Hi all, I need to compare 2 strings,one is a simple character string and the other is a LPWSTR value.How can I do it.Is there any type conversion available. Thanks Abhishek. Learning is a never ending process of Life.

          L Offline
          L Offline
          Le centriste
          wrote on last edited by
          #4

          example:

          USES_CONVERSION;
          LPCSTR s1 = "Hello World!";
          LPCWSTR s2 = L"Hello World!";

          int i = _tcscmp(A2CT(s1), W2CT(s2));

          There is other ways, but more complicated. Michel It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
          - TreeBeard

          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