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. CString question

CString question

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

    Hi, I would like to delete all the characters after ".pvd" in a CString variable. How can I keep all the characters before and including ".pvd" and delete all the characters after it??????? Ehsan Behboudi

    M A 2 Replies Last reply
    0
    • M mr2003

      Hi, I would like to delete all the characters after ".pvd" in a CString variable. How can I keep all the characters before and including ".pvd" and delete all the characters after it??????? Ehsan Behboudi

      M Offline
      M Offline
      Mukkie
      wrote on last edited by
      #2

      CString str = "test.pvd sth" int index = str.Find(".pvd"); if(index == -1) return; str = str.Left(index + 4); It should work, though I did not compile it See CString class header for all possible methods :P

      1 Reply Last reply
      0
      • M mr2003

        Hi, I would like to delete all the characters after ".pvd" in a CString variable. How can I keep all the characters before and including ".pvd" and delete all the characters after it??????? Ehsan Behboudi

        A Offline
        A Offline
        Antti Keskinen
        wrote on last edited by
        #3

        You use the combination of Find and Delete member functions. An example:

        CString csText = "I am .pvd and I rock the world !";

        csText.Delete( csText.Find(".pvd") + strlen(".pvd"), 4000 );

        This code fragment would look for the starting point of the ".pvd", then move forward based on the length of the search string, and delete from this point forwards until 4000 characters are removed or the end of the string is reached (more likely). -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

        C 1 Reply Last reply
        0
        • A Antti Keskinen

          You use the combination of Find and Delete member functions. An example:

          CString csText = "I am .pvd and I rock the world !";

          csText.Delete( csText.Find(".pvd") + strlen(".pvd"), 4000 );

          This code fragment would look for the starting point of the ".pvd", then move forward based on the length of the search string, and delete from this point forwards until 4000 characters are removed or the end of the string is reached (more likely). -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

          C Offline
          C Offline
          Carlos Antollini
          wrote on last edited by
          #4

          Antti Keskinen wrote: csText.Delete( csText.Find(".pvd") + strlen(".pvd"), 4000 ); I think that this doesn't work ;) Carlos Antollini Do you know piFive[^] ?

          A 1 Reply Last reply
          0
          • C Carlos Antollini

            Antti Keskinen wrote: csText.Delete( csText.Find(".pvd") + strlen(".pvd"), 4000 ); I think that this doesn't work ;) Carlos Antollini Do you know piFive[^] ?

            A Offline
            A Offline
            Antti Keskinen
            wrote on last edited by
            #5

            A quick Win32 console application supporting MFC on the .Net 2003: The code issued for the compiler:

            // Create a CString object
            CString csText = "I rock the .pdv world !";

            csText.Delete( csText.Find( ".pdv" ) + (int)strlen(".pdv"), 4000 );

            AfxMessageBox( (LPCTSTR) csText, MB_OK );

            This code fragment, when run, displays the console window and pops up a message box reading: "I rock the .pdv". Logical conclusion: the code works, and your assumption of it's non-functionality was misplaced. I know your reply comment was meant humorous, but please.. I am tired of fixing things that aren't broken just because there are people in the wide world who think they know better. I don't mean anything malicious with this nor do I want to make you feel bad in any way, but I just don't find it funny. If you believe that you have more accurate information over a matter, present it, and perhaps point out the things that are incorrect in the earlier postings. It's just that this time, I was correct, you were wrong, and the code worked flawlessly and did precise what it was supposed to do. Perhaps next time, the situation will be reversed, and I'll be the one in need of learning new stuff :) -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

            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