Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: "\b" not "back spacing"?

  1. #1
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question "\b" not "back spacing"?

    Correct me if I'm wrong here but \b is supposed to remove the last letter in a string like \n is supposed to go to a new line.

    For what ever reason \b is not backspacing but instead my a character ""

    heres my code:
    System.out.print("This is a test.\b\n");

    what i expect the out print to be is
    This is a test
    but instead i get:
    This is a test.

    I don't really see what I am doing wrong here.


  2. #2
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: "\b" not "back spacing"?

    the character its out printing is binary.png for some reason it didnt post it.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,943
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: "\b" not "back spacing"?

    What happens when you have control characters being displayed by a program is up to the program.
    Each program can do its own thing when it reads and displays a control character.

  4. #4
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: "\b" not "back spacing"?

    so how would I make it read \b and know to remove one character back?

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,943
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: "\b" not "back spacing"?

    how would I make it read \b
    What is the "it"?
    You could write a method that takes a String as input, scans for the \b character and does some substrings to create a new String with the \b and the character removed.

  6. #6
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: "\b" not "back spacing"?

    You could override printwriter and then set the System.out, although it seems like a lot of effort for not very much gain.

    EG:

    import java.io.PrintWriter;
     
    public class PrintWriter2 extends PrintWriter
    {
      public PrintWriter2(OutputStream out)
      {
         super(out);
      }
      @Override
      public void print(String mes)
      {
         //Modify the message however you like
         super.print(mes);
      }
    }

    Then in the main method

    PrintWriter newPrintWriter = new PrintWriter2(System.out);
    System.setOut(newPrintWriter);

    Edit, Norm's method might be better.

  7. #7
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: "\b" not "back spacing"?

    alright i got it working thanks

Similar Threads

  1. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  2. Replies: 7
    Last Post: August 13th, 2011, 02:22 AM
  3. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  4. Java says:"Hello World". I say:"It works!"
    By Davidovic in forum Member Introductions
    Replies: 4
    Last Post: June 29th, 2010, 08:13 AM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM