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 to remove a character in Console

How to remove a character in Console

Scheduled Pinned Locked Moved C#
tutorialquestion
6 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.
  • H Offline
    H Offline
    humblepgmr
    wrote on last edited by
    #1

    Hi all, Not sure if this is possible, but in a console app, is it possible to move the cursor 1 space to the left and replace the console text with a space (clearing last keystroke)? Thanks in advance

    P L 2 Replies Last reply
    0
    • H humblepgmr

      Hi all, Not sure if this is possible, but in a console app, is it possible to move the cursor 1 space to the left and replace the console text with a space (clearing last keystroke)? Thanks in advance

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Write out a '\b' (backspace) character.

      H 1 Reply Last reply
      0
      • P PIEBALDconsult

        Write out a '\b' (backspace) character.

        H Offline
        H Offline
        humblepgmr
        wrote on last edited by
        #3

        I tried that and I'm finding that it's not deleting, the cursor doesn't delete, it just goes back to the same pos. System.Console.WriteLine("*******************************"); System.Console.WriteLine("Press 'Q' to Quit "); System.Console.WriteLine("Press 'A' to go again"); System.Console.WriteLine("Press 'N' to start"); System.Console.WriteLine("*******************************"); do { try{ System.Console.Write("\b"); stop = validate(System.Console.ReadKey().KeyChar); //Return false if != (q,a,n) if (!stop) { System.Console.Write("\b"); } }catch(System.Exception){ stop = false; } } while (!stop);

        A 1 Reply Last reply
        0
        • H humblepgmr

          I tried that and I'm finding that it's not deleting, the cursor doesn't delete, it just goes back to the same pos. System.Console.WriteLine("*******************************"); System.Console.WriteLine("Press 'Q' to Quit "); System.Console.WriteLine("Press 'A' to go again"); System.Console.WriteLine("Press 'N' to start"); System.Console.WriteLine("*******************************"); do { try{ System.Console.Write("\b"); stop = validate(System.Console.ReadKey().KeyChar); //Return false if != (q,a,n) if (!stop) { System.Console.Write("\b"); } }catch(System.Exception){ stop = false; } } while (!stop);

          A Offline
          A Offline
          Anthony Mushrow
          wrote on last edited by
          #4

          Write out a backspace character, then a space! The space overwites the last char. Not sure how you would actually remove it completely but, y'know. Console.Write("\b "); Should replace the last char with a space.

          My current favourite word is: Waffle Cheese is still good though.

          1 Reply Last reply
          0
          • H humblepgmr

            Hi all, Not sure if this is possible, but in a console app, is it possible to move the cursor 1 space to the left and replace the console text with a space (clearing last keystroke)? Thanks in advance

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Console.Write("\b \b"); should do it. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


            P 1 Reply Last reply
            0
            • L Luc Pattyn

              Console.Write("\b \b"); should do it. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              Oh, sure, just give him the whole solution, geeze. :-D

              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