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#
  4. how can I clear out null characters in a string var?

how can I clear out null characters in a string var?

Scheduled Pinned Locked Moved C#
question
3 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.
  • D Offline
    D Offline
    djkno3
    wrote on last edited by
    #1

    I read in a chunk of a file in bytes, converted it to ascii, made it a string and now I am trying to clear out the '\0' characters. Any advice?

    J 1 Reply Last reply
    0
    • D djkno3

      I read in a chunk of a file in bytes, converted it to ascii, made it a string and now I am trying to clear out the '\0' characters. Any advice?

      J Offline
      J Offline
      Jeff Varszegi
      wrote on last edited by
      #2

      The simplest single-line call is to do this: <your string>.Replace('\0'.ToString(), "")); or <your string>.Replace("\0", "")); I would probably recommend stripping unneeded chars as you're reading in the bytes, or when you convert to ascii, if you're doing that work yourself and can find a good place to insert the logic; it'd probably be faster that way. -Jeff here, bloggy bloggy

      D 1 Reply Last reply
      0
      • J Jeff Varszegi

        The simplest single-line call is to do this: <your string>.Replace('\0'.ToString(), "")); or <your string>.Replace("\0", "")); I would probably recommend stripping unneeded chars as you're reading in the bytes, or when you convert to ascii, if you're doing that work yourself and can find a good place to insert the logic; it'd probably be faster that way. -Jeff here, bloggy bloggy

        D Offline
        D Offline
        djkno3
        wrote on last edited by
        #3

        dammit I knew it was somthing simple like that ;) thanks

        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