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. Convert CString to Unsigned Long

Convert CString to Unsigned Long

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
5 Posts 5 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.
  • C Offline
    C Offline
    Caoimh
    wrote on last edited by
    #1

    I need to convert CString string to unsigned long. Exammple Need CString strPacket = "FFFFF400" to unsigned long Also any idea how to add a value to strPacket. What I mean is strPacket = "FFFFF400" + "4" = "FFFFF404";

    T D Michael HaephratiM 3 Replies Last reply
    0
    • C Caoimh

      I need to convert CString string to unsigned long. Exammple Need CString strPacket = "FFFFF400" to unsigned long Also any idea how to add a value to strPacket. What I mean is strPacket = "FFFFF400" + "4" = "FFFFF404";

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      sscanf((LPCTSTR)strPacket, "%ul", &myulVar); simple, rustik.... assuming that your string is a valid unsigned long value...

      TOXCCT >>> GEII power

      1 Reply Last reply
      0
      • C Caoimh

        I need to convert CString string to unsigned long. Exammple Need CString strPacket = "FFFFF400" to unsigned long Also any idea how to add a value to strPacket. What I mean is strPacket = "FFFFF400" + "4" = "FFFFF404";

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Caoimh wrote: I need to convert CString string to unsigned long. Use strtoul() for this. Caoimh wrote: Also any idea how to add a value to strPacket. What I mean is strPacket = "FFFFF400" + "4" = "FFFFF404"; Assuming that strPacket is a CString object, this is perfectly valid:

        strPacket = "FFFFF400"; // assignment
        strPacket += "4"; // concatenation


        "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

        S 1 Reply Last reply
        0
        • D David Crow

          Caoimh wrote: I need to convert CString string to unsigned long. Use strtoul() for this. Caoimh wrote: Also any idea how to add a value to strPacket. What I mean is strPacket = "FFFFF400" + "4" = "FFFFF404"; Assuming that strPacket is a CString object, this is perfectly valid:

          strPacket = "FFFFF400"; // assignment
          strPacket += "4"; // concatenation


          "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          (cough) Actually, I think they meant unsigned long x; unsigned long y; x = strtoul(str,NULL,16); y = strtoul(str2, NULL,16); strPacket.Format("%08lx", x+y); Steve S

          1 Reply Last reply
          0
          • C Caoimh

            I need to convert CString string to unsigned long. Exammple Need CString strPacket = "FFFFF400" to unsigned long Also any idea how to add a value to strPacket. What I mean is strPacket = "FFFFF400" + "4" = "FFFFF404";

            Michael HaephratiM Offline
            Michael HaephratiM Offline
            Michael Haephrati
            wrote on last edited by
            #5

            I usually use

            _wtol(cstringvar)

            - Michael Haephrati מיכאל האפרתי

            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