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. How i remove a part of a string

How i remove a part of a string

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

    CString Test = "Remove the word TEST" how i remove the TEST ? so i gonna have CString Test = "Remove the word "

    B A 2 Replies Last reply
    0
    • I Immunity18

      CString Test = "Remove the word TEST" how i remove the TEST ? so i gonna have CString Test = "Remove the word "

      B Offline
      B Offline
      bob16972
      wrote on last edited by
      #2

      CString sData="Remove the word TEST"; CString sWord="TEST"; int nIndex=sData.Find(sWord,0); if (nIndex!=(-1)) { // Found it sData.Delete(nIndex,sWord.GetLength()); } TRACE("%s",sData);

      I 1 Reply Last reply
      0
      • B bob16972

        CString sData="Remove the word TEST"; CString sWord="TEST"; int nIndex=sData.Find(sWord,0); if (nIndex!=(-1)) { // Found it sData.Delete(nIndex,sWord.GetLength()); } TRACE("%s",sData);

        I Offline
        I Offline
        Immunity18
        wrote on last edited by
        #3

        thank you very much bob16972 you helped me much today :D

        1 Reply Last reply
        0
        • I Immunity18

          CString Test = "Remove the word TEST" how i remove the TEST ? so i gonna have CString Test = "Remove the word "

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

          Another method is : CString Test = "Remove the word TEST"; Test.Replace("TEST","");

          B 1 Reply Last reply
          0
          • A anwer_skk

            Another method is : CString Test = "Remove the word TEST"; Test.Replace("TEST","");

            B Offline
            B Offline
            bob16972
            wrote on last edited by
            #5

            That'll remove every instance of the word "TEST". The other will remove the first instance only. Just a heads up for the sake of clarity. For what it's worth...

            A T 2 Replies Last reply
            0
            • B bob16972

              That'll remove every instance of the word "TEST". The other will remove the first instance only. Just a heads up for the sake of clarity. For what it's worth...

              A Offline
              A Offline
              anwer_skk
              wrote on last edited by
              #6

              yes that is true, btw what she/he wanted exactly ?

              B 1 Reply Last reply
              0
              • A anwer_skk

                yes that is true, btw what she/he wanted exactly ?

                B Offline
                B Offline
                bob16972
                wrote on last edited by
                #7

                Honestly I'm not sure at this point. You were right in posting your stuff. I wasn't jumping on it. I just threw in the clarification for they're benefit so they knew the implications of each method. Sorry if I approached that wrong. It never dawned on me that the user might want all instances removed so I'm glad you caught that. Thanks and take care.

                1 Reply Last reply
                0
                • B bob16972

                  That'll remove every instance of the word "TEST". The other will remove the first instance only. Just a heads up for the sake of clarity. For what it's worth...

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #8

                  bob16972 wrote:

                  That'll remove every instance of the word "TEST". The other will remove the first instance only

                  In that case how will he/she determine which TEST keyword he have to removed

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                  cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                  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