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. extract a substring from CString

extract a substring from CString

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structureshelpquestionlearning
2 Posts 2 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
    Tryhard
    wrote on last edited by
    #1

    Hi all, I am new to C++ and I have to say my biggest hurdle is getting my head around what operations I can do with the various var types. It seems everytime I try and do anything with a CString I get an error telling my 'can't convert CString to char *' or various errors all along these lines. Anyway I think I am starting to get there :-) I need to extract a substring from a CString. i.e. CString = "This is a test string" say i need to get the word test out and store it in an word array. I know what position it starts and i know what position it ends, so I of course know how many chars I need. What should I use to get that word from the CString and stick it in say word_array[word_count]??? Any pointers are greatly appreciated, Cheers Dudes, Tryhard Down Under PS - Thanks to all who have replied to my previous posts esp. C.G. Thanks Dude, very helpfull :-) Tryhard :-)

    C 1 Reply Last reply
    0
    • T Tryhard

      Hi all, I am new to C++ and I have to say my biggest hurdle is getting my head around what operations I can do with the various var types. It seems everytime I try and do anything with a CString I get an error telling my 'can't convert CString to char *' or various errors all along these lines. Anyway I think I am starting to get there :-) I need to extract a substring from a CString. i.e. CString = "This is a test string" say i need to get the word test out and store it in an word array. I know what position it starts and i know what position it ends, so I of course know how many chars I need. What should I use to get that word from the CString and stick it in say word_array[word_count]??? Any pointers are greatly appreciated, Cheers Dudes, Tryhard Down Under PS - Thanks to all who have replied to my previous posts esp. C.G. Thanks Dude, very helpfull :-) Tryhard :-)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      To get a substring out of a CString you can use left, mid, or right. For example, in the above example you could use CString s = "This is a test string"; CString y = s.Mid(10, 4); As usual, you can use SetBuffer and ReleaseBuffer in order to get the underlying data if you need to. Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.

      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