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. scan string for characters \ / ? * : "

scan string for characters \ / ? * : "

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 6 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.
  • R Offline
    R Offline
    rolfhorror
    wrote on last edited by
    #1

    any easy way to scan a string that a user inputs in an editbox control, for characters and remove them from the string? charachters like: \ / ? * : " < > | say i have this function... void CMyDlg::OnCheck() { GetDlgItemText(IDC_EDIT1, str); //do a scan of the string to see if it contains the characters \ / ? * : " < > | //remove them from the string //return the string without the characters MessageBox("Your string: "+str,""); } or any other way to only let the user input only a-z and A-Z characters in the editbox? thanks.

    J CPalliniC M D J 5 Replies Last reply
    0
    • R rolfhorror

      any easy way to scan a string that a user inputs in an editbox control, for characters and remove them from the string? charachters like: \ / ? * : " < > | say i have this function... void CMyDlg::OnCheck() { GetDlgItemText(IDC_EDIT1, str); //do a scan of the string to see if it contains the characters \ / ? * : " < > | //remove them from the string //return the string without the characters MessageBox("Your string: "+str,""); } or any other way to only let the user input only a-z and A-Z characters in the editbox? thanks.

      J Offline
      J Offline
      Joan M
      wrote on last edited by
      #2

      you can take advantage of CString. There is a member function that wil automatically remove the chars or substrings that you pass to it. I think it's called .Remove(""); You should call:

      UpdateData();
      editboxstring.Remove("/");

      From the MSDN:

      CString::Remove
      int CString::Remove( TCHAR ch );

      Return Value

      The count of characters removed from the string. Zero if the string isn't changed.

      Parameters

      ch

      The character to be removed from a string.

      Remarks

      Call this member function to remove instances of ch from the string. Comparisons for the character are case-sensitive.

      Example

      //remove the lower-case letter 't' from a sentence:

      CString str("This is a test.");
      int n = str.Remove('t');
      ASSERT(n == 2);
      ASSERT(str == "This is a es.");

      https://www.robotecnik.com freelance robots, PLC and CNC programmer.

      R 1 Reply Last reply
      0
      • R rolfhorror

        any easy way to scan a string that a user inputs in an editbox control, for characters and remove them from the string? charachters like: \ / ? * : " < > | say i have this function... void CMyDlg::OnCheck() { GetDlgItemText(IDC_EDIT1, str); //do a scan of the string to see if it contains the characters \ / ? * : " < > | //remove them from the string //return the string without the characters MessageBox("Your string: "+str,""); } or any other way to only let the user input only a-z and A-Z characters in the editbox? thanks.

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        have a look at CString::Remove. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        • R rolfhorror

          any easy way to scan a string that a user inputs in an editbox control, for characters and remove them from the string? charachters like: \ / ? * : " < > | say i have this function... void CMyDlg::OnCheck() { GetDlgItemText(IDC_EDIT1, str); //do a scan of the string to see if it contains the characters \ / ? * : " < > | //remove them from the string //return the string without the characters MessageBox("Your string: "+str,""); } or any other way to only let the user input only a-z and A-Z characters in the editbox? thanks.

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          CString::Remove() will do that, although you'll need to call it once for each character.

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

          1 Reply Last reply
          0
          • J Joan M

            you can take advantage of CString. There is a member function that wil automatically remove the chars or substrings that you pass to it. I think it's called .Remove(""); You should call:

            UpdateData();
            editboxstring.Remove("/");

            From the MSDN:

            CString::Remove
            int CString::Remove( TCHAR ch );

            Return Value

            The count of characters removed from the string. Zero if the string isn't changed.

            Parameters

            ch

            The character to be removed from a string.

            Remarks

            Call this member function to remove instances of ch from the string. Comparisons for the character are case-sensitive.

            Example

            //remove the lower-case letter 't' from a sentence:

            CString str("This is a test.");
            int n = str.Remove('t');
            ASSERT(n == 2);
            ASSERT(str == "This is a es.");

            R Offline
            R Offline
            rolfhorror
            wrote on last edited by
            #5

            thanks, this really helped a lot, it worked like a charm.

            1 Reply Last reply
            0
            • R rolfhorror

              any easy way to scan a string that a user inputs in an editbox control, for characters and remove them from the string? charachters like: \ / ? * : " < > | say i have this function... void CMyDlg::OnCheck() { GetDlgItemText(IDC_EDIT1, str); //do a scan of the string to see if it contains the characters \ / ? * : " < > | //remove them from the string //return the string without the characters MessageBox("Your string: "+str,""); } or any other way to only let the user input only a-z and A-Z characters in the editbox? thanks.

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

              hobbyprogrammer wrote:

              //do a scan of the string to see if it contains the characters \ / ? * : " < > | //remove them from the string //return the string without the characters

              Why not just disalloow them to begin with?


              "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

              "Judge not by the eye but by the heart." - Native American Proverb

              1 Reply Last reply
              0
              • R rolfhorror

                any easy way to scan a string that a user inputs in an editbox control, for characters and remove them from the string? charachters like: \ / ? * : " < > | say i have this function... void CMyDlg::OnCheck() { GetDlgItemText(IDC_EDIT1, str); //do a scan of the string to see if it contains the characters \ / ? * : " < > | //remove them from the string //return the string without the characters MessageBox("Your string: "+str,""); } or any other way to only let the user input only a-z and A-Z characters in the editbox? thanks.

                J Offline
                J Offline
                James R Twine
                wrote on last edited by
                #7

                hobbyprogrammer wrote:

                or any other way to only let the user input only a-z and A-Z characters in the editbox?

                You can have look at http://www.codeproject.com/editctrl/enhfocusedit.asp[^] for some ideas on how to filter the input.    Peace!

                -=- James


                If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                DeleteFXPFiles & CheckFavorites (Please rate this post!)

                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