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. Managed C++/CLI
  4. How to remove a non-ascii character from CString

How to remove a non-ascii character from CString

Scheduled Pinned Locked Moved Managed C++/CLI
questiontutorial
7 Posts 3 Posters 3 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.
  • E Offline
    E Offline
    Erich Ruth
    wrote on last edited by
    #1

    I find that some of the data I bring in has a character that looks like a space but is not a space. After much research, I identified the character as & then #160; If I put it together, it looks like a space in this message. How can I remove characters like this? I tried CString GetRidOf(CString str) { str.Remove(' '); return str; } but the remove function is not correct.

    P L 2 Replies Last reply
    0
    • E Erich Ruth

      I find that some of the data I bring in has a character that looks like a space but is not a space. After much research, I identified the character as & then #160; If I put it together, it looks like a space in this message. How can I remove characters like this? I tried CString GetRidOf(CString str) { str.Remove(' '); return str; } but the remove function is not correct.

      P Offline
      P Offline
      phil o
      wrote on last edited by
      #2

      You could try

      str.Remove('\xA0');

      A0 is the hexadecimal representation of the decimal value 160. It should represent a non-breaking-space.

      "Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."

      E 1 Reply Last reply
      0
      • E Erich Ruth

        I find that some of the data I bring in has a character that looks like a space but is not a space. After much research, I identified the character as & then #160; If I put it together, it looks like a space in this message. How can I remove characters like this? I tried CString GetRidOf(CString str) { str.Remove(' '); return str; } but the remove function is not correct.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        MSDN states[^] wrote:

        This method does not modify the value of the current instance. Instead, it returns a new string in which all characters from position startIndex to the end of the original string have been removed.

        So, assign the result of the function to a new string and return that, or return the result of the function.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

        P 1 Reply Last reply
        0
        • P phil o

          You could try

          str.Remove('\xA0');

          A0 is the hexadecimal representation of the decimal value 160. It should represent a non-breaking-space.

          "Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."

          E Offline
          E Offline
          Erich Ruth
          wrote on last edited by
          #4

          That worked. Thank you very much.

          P 1 Reply Last reply
          0
          • L Lost User

            MSDN states[^] wrote:

            This method does not modify the value of the current instance. Instead, it returns a new string in which all characters from position startIndex to the end of the original string have been removed.

            So, assign the result of the function to a new string and return that, or return the result of the function.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

            P Offline
            P Offline
            phil o
            wrote on last edited by
            #5

            The CString version does not work like the .NET one: CString::Remove[^]

            "Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."

            L 1 Reply Last reply
            0
            • E Erich Ruth

              That worked. Thank you very much.

              P Offline
              P Offline
              phil o
              wrote on last edited by
              #6

              You are welcome.

              "Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."

              1 Reply Last reply
              0
              • P phil o

                The CString version does not work like the .NET one: CString::Remove[^]

                "Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                :laugh: Tx for pointing that out :thumbsup:

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                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